@@ -5,7 +5,7 @@ import { createAPIFileRoute } from '@tanstack/start/api';
55import { SanityClient } from 'sanity' ;
66import { sendRedirect , setCookie } from 'vinxi/http' ;
77
8- export const APIRoute = createAPIFileRoute ( '/api/studio/ preview-mode/enable' ) ( {
8+ export const APIRoute = createAPIFileRoute ( '/api/preview-mode/enable' ) ( {
99 GET : async ( { request } ) => {
1010 if ( ! process . env . SANITY_VIEWER_TOKEN ) {
1111 throw new Response ( 'Preview mode missing token' , { status : 401 } ) ;
@@ -15,17 +15,22 @@ export const APIRoute = createAPIFileRoute('/api/studio/preview-mode/enable')({
1515 token : process . env . SANITY_VIEWER_TOKEN ,
1616 } ) ;
1717
18- const {
19- isValid ,
20- redirectTo = '/' ,
21- } = await validatePreviewUrl ( clientWithToken , request . url ) ;
18+ const { isValid , redirectTo = '/' } = await validatePreviewUrl (
19+ clientWithToken ,
20+ request . url ,
21+ ) ;
2222
2323 if ( ! isValid ) {
2424 throw new Response ( 'Invalid secret' , { status : 401 } ) ;
2525 }
2626
2727 // we can use sameSite: 'strict' because we're running an embedded studio
28- setCookie ( '__sanity_preview' , randomBytes ( 16 ) . toString ( 'hex' ) , { path : '/' , secure : import . meta. env . PROD , httpOnly : true , sameSite : 'strict' } ) ;
29- sendRedirect ( redirectTo )
28+ setCookie ( '__sanity_preview' , randomBytes ( 16 ) . toString ( 'hex' ) , {
29+ path : '/' ,
30+ secure : import . meta. env . PROD ,
31+ httpOnly : true ,
32+ sameSite : 'strict' ,
33+ } ) ;
34+ sendRedirect ( redirectTo ) ;
3035 } ,
3136} ) ;
0 commit comments