File tree Expand file tree Collapse file tree 4 files changed +58
-19
lines changed
Expand file tree Collapse file tree 4 files changed +58
-19
lines changed Original file line number Diff line number Diff line change @@ -25,18 +25,23 @@ export default function SocialButtons({
2525 const supabase = getSupabaseBrowserClient ( ) ;
2626 const pathname = usePathname ( ) ;
2727 const oauthRedirectUrl = useMemo ( ( ) => {
28- if ( ! process . env . NEXT_PUBLIC_ROOT_URL ) {
29- return undefined ;
30- }
28+ const lang = pathname ?. split ( '/' ) [ 1 ] || 'en' ;
29+ const siteOrigin =
30+ ( typeof window !== 'undefined' && window . location . origin ) ||
31+ process . env . NEXT_PUBLIC_ROOT_URL ;
3132
32- const normalizedRoot = process . env . NEXT_PUBLIC_ROOT_URL . replace ( / \/ $ / , '' ) ;
33+ if ( ! siteOrigin ) return undefined ;
34+
35+ const normalizedSiteOrigin = siteOrigin . replace ( / \/ $ / , '' ) ;
3336
3437 // If we're on the sign-in page, redirect to home after successful login
3538 const nextPath = pathname ?. includes ( '/sign-in' )
3639 ? pathname . replace ( / \/ s i g n - i n .* $ / , '' ) || '/'
3740 : pathname || '/' ;
3841
39- return `${ normalizedRoot } /auth/callback?next=${ encodeURIComponent ( nextPath ) } ` ;
42+ const nextUrl = `${ normalizedSiteOrigin } ${ nextPath } ?lang=${ lang } ` ;
43+ const nextParam = encodeURIComponent ( nextUrl ) ;
44+ return `${ normalizedSiteOrigin } /auth/callback?next=${ nextParam } ` ;
4045 } , [ pathname ] ) ;
4146
4247 const socialButtons : SocialButton [ ] = [
Original file line number Diff line number Diff line change @@ -41,21 +41,24 @@ export async function proxy(
4141 NEXT_PUBLIC_SUPABASE_ANON_KEY ,
4242 {
4343 cookies : {
44- getAll ( ) {
45- return req . cookies . getAll ( ) ;
44+ get ( name ) {
45+ return req . cookies . get ( name ) ?. value ;
4646 } ,
47- setAll ( cookiesToSet ) {
48- cookiesToSet . forEach ( ( { name, value, options} ) => {
49- req . cookies . set ( name , value ) ;
50- res . cookies . set ( name , value , options ) ;
51- } ) ;
47+ set ( name , value , options ) {
48+ res . cookies . set ( name , value , options ) ;
49+ } ,
50+ remove ( name , options ) {
51+ res . cookies . set ( name , '' , { ... options , maxAge : 0 } ) ;
5252 } ,
5353 } ,
5454 } ,
5555 ) ;
56+
5657 const {
57- data : { user} ,
58- } = await supabase . auth . getUser ( ) ;
58+ data : { session} ,
59+ } = await supabase . auth . getSession ( ) ;
60+
61+ const user = session ?. user ;
5962
6063 if ( user ) {
6164 upsertUser ( { supabase, user} ) ;
Original file line number Diff line number Diff line change @@ -1499,11 +1499,6 @@ input[type='search']::-webkit-search-decoration,
14991499 min-width : 70px ;
15001500}
15011501
1502- .min-w-fit {
1503- min-width : -moz-fit-content;
1504- min-width : fit-content;
1505- }
1506-
15071502.min-w-full {
15081503 min-width : 100% ;
15091504}
Original file line number Diff line number Diff line change 1+ import { createServerClient } from '@supabase/ssr' ;
2+ import { NextResponse } from 'next/server' ;
3+ import type { NextRequest } from 'next/server' ;
4+
5+ import type { Database } from '~/types/supabase' ;
6+
7+ export async function updateSession ( request : NextRequest ) : Promise < NextResponse > {
8+ let response = NextResponse . next ( {
9+ request : {
10+ headers : request . headers ,
11+ } ,
12+ } ) ;
13+
14+ const supabase = createServerClient < Database > (
15+ process . env . NEXT_PUBLIC_SUPABASE_URL || '' ,
16+ process . env . NEXT_PUBLIC_SUPABASE_ANON_KEY || '' ,
17+ {
18+ cookies : {
19+ get ( name ) {
20+ return request . cookies . get ( name ) ?. value ;
21+ } ,
22+ set ( name , value , options ) {
23+ response . cookies . set ( name , value , options ) ;
24+ } ,
25+ remove ( name , options ) {
26+ response . cookies . set ( name , '' , { ...options , maxAge : 0 } ) ;
27+ } ,
28+ } ,
29+ } ,
30+ ) ;
31+
32+ // Refresh session if needed and forward cookies to client
33+ await supabase . auth . getSession ( ) ;
34+
35+ return response ;
36+ }
You can’t perform that action at this time.
0 commit comments