-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started sign in - sign out flow; WIP
- Loading branch information
Showing
5 changed files
with
92 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// app/api/auth-change/route.ts | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { createServerClient, CookieOptions } from '@supabase/ssr'; | ||
|
||
export async function POST(request: NextRequest) { | ||
const { event, session } = await request.json(); | ||
|
||
// Initialize Supabase client with SSR capabilities | ||
const supabase = createServerClient( | ||
process.env.NEXT_PUBLIC_SUPABASE_URL!, | ||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, | ||
{ | ||
cookies: { | ||
get(name: string) { | ||
return request.cookies.get(name)?.value || null; | ||
}, | ||
set(name: string, value: string, options: CookieOptions) { | ||
request.cookies.set({ | ||
name, | ||
value, | ||
...options, | ||
}); | ||
}, | ||
remove(name: string, options: CookieOptions) { | ||
request.cookies.set({ | ||
name, | ||
value: '', | ||
...options, | ||
}); | ||
}, | ||
}, | ||
} | ||
); | ||
|
||
if (event === 'SIGNED_IN') { | ||
// Handle user sign in | ||
if (session) { | ||
// Update session cookies | ||
const response = NextResponse.json({ message: 'User signed in' }); | ||
response.cookies.set('supabase-auth-token', session.access_token, { | ||
httpOnly: true, | ||
path: '/', | ||
}); | ||
return response; | ||
} | ||
} else if (event === 'SIGNED_OUT') { | ||
// Handle user sign out | ||
const response = NextResponse.json({ message: 'User signed out' }); | ||
response.cookies.delete('supabase-auth-token'); | ||
return response; | ||
} | ||
|
||
return NextResponse.json({ message: 'Auth state change handled' }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters