Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions app/(auth)/callback/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createClient } from '@/lib/supabase/server'
import { publicRedirectUrl } from '@/lib/public-url'
import { NextResponse } from 'next/server'
import { redirect } from 'next/navigation'

export async function GET(request: Request) {
const requestUrl = new URL(request.url)
Expand All @@ -25,20 +24,20 @@ export async function GET(request: Request) {
const redirectPath = existingRole.role === 'student'
? '/student/dashboard'
: '/educator/dashboard'
return NextResponse.redirect(publicRedirectUrl(request, redirectPath))
redirect(redirectPath)
}

// Check role from metadata and route to onboarding
const role = user.user_metadata?.role

if (role === 'student') {
return NextResponse.redirect(publicRedirectUrl(request, '/student/onboarding'))
redirect('/student/onboarding')
} else if (role === 'educator') {
return NextResponse.redirect(publicRedirectUrl(request, '/educator/onboarding'))
redirect('/educator/onboarding')
}
}
}

// If no code or error, redirect to home
return NextResponse.redirect(publicRedirectUrl(request, '/'))
redirect('/')
}
13 changes: 6 additions & 7 deletions app/api/auth/confirm/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {UserRole} from "@/domains/auth/types";
import {publicRedirectUrl} from "@/lib/public-url";
import {createClient} from "@/lib/supabase/server";
import {NextResponse} from "next/server";
import {redirect} from "next/navigation";

export async function GET(request: Request) {
const requestUrl = new URL(request.url);
Expand Down Expand Up @@ -30,27 +29,27 @@ export async function GET(request: Request) {
if (existingRole) {
// User already onboarded, redirect to their dashboard
const dashboardPath = existingRole.role === "student" ? "/student/dashboard" : "/educator/dashboard";
return NextResponse.redirect(publicRedirectUrl(request, dashboardPath));
redirect(dashboardPath);
}

// User has NOT completed onboarding, check their role from metadata
const role: UserRole = user.user_metadata?.role;

if (role === "student") {
return NextResponse.redirect(publicRedirectUrl(request, "/student/onboarding"));
redirect("/student/onboarding");
} else if (role === "instructor") {
return NextResponse.redirect(publicRedirectUrl(request, "/educator/onboarding"));
redirect("/educator/onboarding");
}
}

// Default redirect if no role found (resolve next relative to request)
// Sanitize next to prevent open redirect - only allow internal paths
const safeNext =
next.startsWith("/") && !next.startsWith("//") ? next : "/";
return NextResponse.redirect(publicRedirectUrl(request, safeNext));
redirect(safeNext);
}
}

// If error or no token, redirect to error page
return NextResponse.redirect(publicRedirectUrl(request, "/auth/auth-error"));
redirect("/auth/auth-error");
}
24 changes: 0 additions & 24 deletions lib/public-url.ts

This file was deleted.