Skip to content

Commit

Permalink
Merge pull request #48 from diggerhq/fix/login-onboarding-session
Browse files Browse the repository at this point in the history
Use actual user instead of session for onboarding redirect
  • Loading branch information
ZIJ authored Sep 13, 2024
2 parents 20153ba + 86c6f33 commit b737be7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ export async function middleware(req: NextRequest) {
const supabase = createMiddlewareClient<Database>({ req, res });
const sessionResponse = await supabase.auth.getSession();
const maybeUser = sessionResponse?.data.session?.user;
if (shouldOnboardUser(req.nextUrl.pathname, maybeUser)) {
return NextResponse.redirect(toSiteURL('/onboarding'));
}
if (isLandingPage(req.nextUrl.pathname)) {
if (maybeUser) {
//user is logged in, lets validate session and redirect on success
Expand All @@ -100,6 +97,9 @@ export async function middleware(req: NextRequest) {
if (user.error) {
return NextResponse.redirect(toSiteURL('/login'));
}
if (shouldOnboardUser(req.nextUrl.pathname, user.data.user)) {
return NextResponse.redirect(toSiteURL('/onboarding'));
}
}
if (!isUnprotectedPage(req.nextUrl.pathname) && !maybeUser) {
return NextResponse.redirect(toSiteURL('/login'));
Expand Down

0 comments on commit b737be7

Please sign in to comment.