docs: improve auth flow documentation and fix email confirmation redirect
**Auth Callback Improvements:** - Fix default redirect from /clients to /epd/clients (correct route) - Add smart detection for password vs magic link users - Password signup users now go directly to /epd/clients after email confirmation - Magic link users still get optional /set-password page **Documentation:** - Add comprehensive AUTH_FLOW_EXPLAINED.md with step-by-step flow diagrams - Update RELEASE_AUTH_IMPROVEMENTS.md with magic link migration instructions - Update emails/README.md with aispeedrun.nl redirect URL configuration - Document Site URL vs Redirect URLs difference - Add troubleshooting for common issues (localhost in emails, invalid redirect) **Key Changes:** - Email confirmation now correctly redirects password users to EPD - Clear instructions for Supabase configuration (Site URL + Redirect URLs) - Both development and production URLs documented for dual environment support All documentation includes practical examples and FAQ section. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,7 @@ import type { NextRequest } from 'next/server'
|
||||
export async function GET(request: NextRequest) {
|
||||
const requestUrl = new URL(request.url)
|
||||
const code = requestUrl.searchParams.get('code')
|
||||
const next = requestUrl.searchParams.get('next') ?? '/clients'
|
||||
const next = requestUrl.searchParams.get('next') ?? '/epd/clients'
|
||||
|
||||
if (code) {
|
||||
const supabase = await createClient()
|
||||
@@ -25,12 +25,18 @@ export async function GET(request: NextRequest) {
|
||||
const isNewUser = new Date(data.user.created_at).getTime() ===
|
||||
new Date(data.user.last_sign_in_at || '').getTime()
|
||||
|
||||
if (isNewUser) {
|
||||
// Redirect new users to set-password page
|
||||
// Check if user signed up with password (has identity provider = 'email')
|
||||
const hasPassword = data.user.identities?.some(
|
||||
identity => identity.provider === 'email'
|
||||
)
|
||||
|
||||
if (isNewUser && !hasPassword) {
|
||||
// Redirect new magic link users to set-password page (optional)
|
||||
return NextResponse.redirect(new URL('/set-password', request.url))
|
||||
}
|
||||
|
||||
// Redirect to the specified next URL or default to /clients
|
||||
// Redirect to the specified next URL or default to /epd/clients
|
||||
// This includes: password signups, confirmed email users, and returning users
|
||||
return NextResponse.redirect(new URL(next, request.url))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user