all repos — caroster @ 220ff03121997f1598580fc925bddb276127ac55

[Octree] Group carpool to your event https://caroster.io

fix: :ambulance: Fix broken auth with Google

#481
Tim Izzo tim@5ika.ch
Mon, 29 Jan 2024 17:43:30 +0100
commit

220ff03121997f1598580fc925bddb276127ac55

parent

20bf7086107e834abd260e1b35602ca187d42d9a

3 files changed, 19 insertions(+), 18 deletions(-)

jump to
M DockerfileDockerfile

@@ -1,6 +1,6 @@

FROM git.octree.ch:4567/o/infra/templates/base/strapi:nginx -ENV NEXTAUTH_URL_INTERNAL: http://localhost:3000/api/nauth +ENV NEXTAUTH_URL_INTERNAL http://localhost:3000/api/nauth COPY ./frontend /srv/app/frontend COPY ./backend /srv/app/backend
M backend/src/graphql/user/index.tsbackend/src/graphql/user/index.ts

@@ -92,6 +92,11 @@ },

}, }, resolversConfig: { + "Query.me": { + auth: { + scope: ["plugin::users-permissions.user.me"], + }, + }, "UsersPermissionsUser.notifications": { auth: { scope: ["plugin::users-permissions.user.me"],
M frontend/pages/api/nauth/[...nextauth].jsfrontend/pages/api/nauth/[...nextauth].js

@@ -2,7 +2,7 @@ import NextAuth from 'next-auth';

import CredentialsProvider from 'next-auth/providers/credentials'; import GoogleProvider from 'next-auth/providers/google'; -const {STRAPI_URL = 'http://localhost:1337'} = process.env; +const STRAPI_URL = 'http://localhost:1337'; const authHandler = NextAuth({ providers: [

@@ -45,22 +45,18 @@ const {token, user, account} = params;

// Google Auth if (account?.provider === 'google') { - try { - const strapiUrl = process.env.STRAPI_URL || 'http://localhost:1337'; - const response = await fetch( - `${strapiUrl}/api/auth/${account.provider}/callback?access_token=${account?.access_token}` - ); - const data = await response.json(); - token.id = data.user.id; - token.jwt = data.jwt; - token.email = data.user.email; - token.username = data.user.firstname; - token.lang = data.user.lang?.toLowerCase(); - token.provider = account.provider; - token.userCreatedAt = data.user.createdAt; - } catch (error) { - console.error("Can't authenticate with Google to Strapi: ", error); - } + const strapiUrl = 'http://localhost:1337'; + const response = await fetch( + `${STRAPI_URL}/api/auth/${account.provider}/callback?access_token=${account?.access_token}` + ); + const data = await response.json(); + token.id = data.user.id; + token.jwt = data.jwt; + token.email = data.user.email; + token.username = data.user.firstname; + token.lang = data.user.lang?.toLowerCase(); + token.provider = account.provider; + token.userCreatedAt = data.user.createdAt; } // Strapi Auth