From 2723fdc3904d2f390d79625478ab4903b86e9880 Mon Sep 17 00:00:00 2001 From: Angelo Reale <12191809+angeloreale@users.noreply.github.com> Date: Thu, 8 Feb 2024 14:07:09 +0100 Subject: [PATCH 1/2] ar(fix) fixes server side csrf login --- lib/auth/constants.ts | 16 ++++--- src/app/api/auth/[...nextauth]/route.ts | 1 - src/app/components/client/signup-view.tsx | 1 + src/app/error/page.tsx | 52 +++++++++++++++++++++++ src/app/signin/page.tsx | 12 +++++- src/app/verify/page.tsx | 52 +++++++++++++++++++++++ 6 files changed, 126 insertions(+), 8 deletions(-) create mode 100644 src/app/error/page.tsx create mode 100644 src/app/verify/page.tsx diff --git a/lib/auth/constants.ts b/lib/auth/constants.ts index 840a0cb2..2d31f11f 100644 --- a/lib/auth/constants.ts +++ b/lib/auth/constants.ts @@ -39,9 +39,15 @@ export const authOptions: AuthOptions = { }, }, callbacks: { - // async signIn() { - - // }, + async signIn({ user, account, profile, email, credentials }) { + // extra sign-in checks + return true + }, + async redirect ({url, baseUrl}) { + return url.startsWith(baseUrl) + ? Promise.resolve(url) + : Promise.resolve(baseUrl) + }, async jwt({ user, token }) { if (user) { // Note that this if condition is needed @@ -60,8 +66,8 @@ export const authOptions: AuthOptions = { pages: { signIn: '/signin', signOut: '/', - // error: '/api/rm/v0/auth/error', // Error code passed in query string as ?error= - // verifyRequest: '/api/rm/v0/auth/verify-request', // (used for check email message) + error: '/error', // Error code passed in query string as ?error= + verifyRequest: '/verify', // (used for check email message) // newUser: '/' // New users will be directed here on first sign in (leave the property out if not of interest) }, }; diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index 513940c3..a80e93db 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -1,5 +1,4 @@ // api/auth/route.ts simple poc - // [...nextauth].ts// auth.ts TS-Doc? import NextAuth from 'next-auth'; import { finalAuth } from '@auth/adapter'; diff --git a/src/app/components/client/signup-view.tsx b/src/app/components/client/signup-view.tsx index e89b4f09..cc1174ec 100644 --- a/src/app/components/client/signup-view.tsx +++ b/src/app/components/client/signup-view.tsx @@ -91,6 +91,7 @@ export const VSignUp = ({ providers, user, csrf }: VSignUpProps) => {