From d058e916e552e13d421876e514c18e03eeab1129 Mon Sep 17 00:00:00 2001 From: Waldemar Date: Thu, 26 Dec 2024 13:55:40 +0200 Subject: [PATCH] refactor: preserve prev link after sign in --- app/ui/sign-in/sign-in.tsx | 4 ++-- middleware.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/ui/sign-in/sign-in.tsx b/app/ui/sign-in/sign-in.tsx index 3f5359f..29420b3 100644 --- a/app/ui/sign-in/sign-in.tsx +++ b/app/ui/sign-in/sign-in.tsx @@ -25,7 +25,6 @@ import { APP_TITLE, DEFAULT_ICON_SIZE, } from '@/config/constants/main' -import { ROUTE } from '@/config/constants/routes' import { TAuthProvider, @@ -69,7 +68,8 @@ function SignIn() { setIsLoading((prev) => ({ ...prev, [provider]: true })) try { await signIn(provider, { - callbackUrl: ROUTE.HOME, + // If no callbackUrl is provided, the user will be redirected to the previous page. + // callbackUrl: ROUTE.HOME, }) } catch (err) { if (err instanceof AuthError) { diff --git a/middleware.ts b/middleware.ts index b2a3c9f..94ae62d 100644 --- a/middleware.ts +++ b/middleware.ts @@ -17,7 +17,7 @@ export default auth((req: NextRequest & { auth: TSession }) => { if (req.nextUrl.pathname === ROUTE.SIGNIN) { url.pathname = ROUTE.HOME - return NextResponse.rewrite(url) + return NextResponse.redirect(url) } return NextResponse.next()