@@ -10,10 +10,15 @@ export const GET: APIRoute = async ({ url, cookies, redirect }) => {
1010 ( import . meta. env as Record < string , string | undefined > )
1111 ?. SANITY_API_READ_TOKEN ;
1212
13- // Query params supported: secret, slug, returnTo
14- const secret = url . searchParams . get ( "secret" ) ;
13+ // Query params supported: sanity-preview-secret/secret, sanity-preview-pathname/returnTo, slug, sanity-preview-perspective
14+ const secret =
15+ url . searchParams . get ( "sanity-preview-secret" ) ??
16+ url . searchParams . get ( "secret" ) ;
1517 const slug = url . searchParams . get ( "slug" ) ;
16- const returnTo = url . searchParams . get ( "returnTo" ) ;
18+ const returnTo =
19+ url . searchParams . get ( "sanity-preview-pathname" ) ??
20+ url . searchParams . get ( "returnTo" ) ;
21+ const perspective = url . searchParams . get ( "sanity-preview-perspective" ) ;
1722
1823 if ( ! readToken ) {
1924 console . warn (
@@ -35,11 +40,18 @@ export const GET: APIRoute = async ({ url, cookies, redirect }) => {
3540 destination = "/" ;
3641 }
3742
43+ if ( perspective && ! destination . includes ( "sanity-preview-perspective=" ) ) {
44+ const sep = destination . includes ( "?" ) ? "&" : "?" ;
45+ destination = `${ destination } ${ sep } sanity-preview-perspective=${ encodeURIComponent ( perspective ) } ` ;
46+ }
47+
48+ const isHttps = url . protocol === "https:" ;
3849 cookies . set ( PREVIEW_COOKIE , "true" , {
3950 path : "/" ,
4051 httpOnly : true ,
41- secure : true ,
42- sameSite : "lax" ,
52+ secure : isHttps ,
53+ sameSite : isHttps ? "none" : "lax" ,
54+ partitioned : isHttps ,
4355 } ) ;
4456
4557 return redirect ( destination , 307 ) ;
0 commit comments