Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
dab1c320
Unverified
Commit
dab1c320
authored
Jul 21, 2024
by
Mustafa Ekrem KENTER
Committed by
GitHub
Jul 21, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs: Update cookie handling for Supabase SSR package (#67413)
Co-authored-by:
Lee Robinson
<
me@leerob.io
>
parent
33389471
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
50 deletions
+18
-50
middleware.ts
examples/with-supabase/utils/supabase/middleware.ts
+11
-36
server.ts
examples/with-supabase/utils/supabase/server.ts
+7
-14
No files found.
examples/with-supabase/utils/supabase/middleware.ts
View file @
dab1c320
import
{
createServerClient
,
type
CookieOptions
}
from
"@supabase/ssr"
;
import
{
createServerClient
}
from
"@supabase/ssr"
;
import
{
type
NextRequest
,
NextResponse
}
from
"next/server"
;
import
{
type
NextRequest
,
NextResponse
}
from
"next/server"
;
export
const
updateSession
=
async
(
request
:
NextRequest
)
=>
{
export
const
updateSession
=
async
(
request
:
NextRequest
)
=>
{
...
@@ -17,44 +17,19 @@ export const updateSession = async (request: NextRequest) => {
...
@@ -17,44 +17,19 @@ export const updateSession = async (request: NextRequest) => {
process
.
env
.
NEXT_PUBLIC_SUPABASE_ANON_KEY
!
,
process
.
env
.
NEXT_PUBLIC_SUPABASE_ANON_KEY
!
,
{
{
cookies
:
{
cookies
:
{
get
(
name
:
string
)
{
get
All
(
)
{
return
request
.
cookies
.
get
(
name
)?.
value
;
return
request
.
cookies
.
get
All
()
;
},
},
set
(
name
:
string
,
value
:
string
,
options
:
CookieOptions
)
{
setAll
(
cookiesToSet
)
{
// If the cookie is updated, update the cookies for the request and response
cookiesToSet
.
forEach
(({
name
,
value
})
=>
request
.
cookies
.
set
({
request
.
cookies
.
set
(
name
,
value
),
name
,
);
value
,
...
options
,
});
response
=
NextResponse
.
next
({
request
:
{
headers
:
request
.
headers
,
},
});
response
.
cookies
.
set
({
name
,
value
,
...
options
,
});
},
remove
(
name
:
string
,
options
:
CookieOptions
)
{
// If the cookie is removed, update the cookies for the request and response
request
.
cookies
.
set
({
name
,
value
:
""
,
...
options
,
});
response
=
NextResponse
.
next
({
response
=
NextResponse
.
next
({
request
:
{
request
,
headers
:
request
.
headers
,
},
});
response
.
cookies
.
set
({
name
,
value
:
""
,
...
options
,
});
});
cookiesToSet
.
forEach
(({
name
,
value
,
options
})
=>
response
.
cookies
.
set
(
name
,
value
,
options
),
);
},
},
},
},
},
},
...
...
examples/with-supabase/utils/supabase/server.ts
View file @
dab1c320
import
{
createServerClient
,
type
CookieOptions
}
from
"@supabase/ssr"
;
import
{
createServerClient
}
from
"@supabase/ssr"
;
import
{
cookies
}
from
"next/headers"
;
import
{
cookies
}
from
"next/headers"
;
export
const
createClient
=
()
=>
{
export
const
createClient
=
()
=>
{
...
@@ -9,27 +9,20 @@ export const createClient = () => {
...
@@ -9,27 +9,20 @@ export const createClient = () => {
process
.
env
.
NEXT_PUBLIC_SUPABASE_ANON_KEY
!
,
process
.
env
.
NEXT_PUBLIC_SUPABASE_ANON_KEY
!
,
{
{
cookies
:
{
cookies
:
{
get
(
name
:
string
)
{
get
All
(
)
{
return
cookieStore
.
get
(
name
)?.
value
;
return
cookieStore
.
get
All
()
;
},
},
set
(
name
:
string
,
value
:
string
,
options
:
CookieOptions
)
{
set
All
(
cookiesToSet
)
{
try
{
try
{
cookieStore
.
set
({
name
,
value
,
...
options
});
cookiesToSet
.
forEach
(({
name
,
value
,
options
})
=>
{
cookieStore
.
set
(
name
,
value
,
options
);
});
}
catch
(
error
)
{
}
catch
(
error
)
{
// The `set` method was called from a Server Component.
// The `set` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// This can be ignored if you have middleware refreshing
// user sessions.
// user sessions.
}
}
},
},
remove
(
name
:
string
,
options
:
CookieOptions
)
{
try
{
cookieStore
.
set
({
name
,
value
:
""
,
...
options
});
}
catch
(
error
)
{
// The `delete` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
},
},
},
},
);
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment