@@ -19,19 +19,6 @@ export default async function handler(
1919
2020 const { resource_id, path, url } = req . query ;
2121
22- let returnTo = state && ! state . startsWith ( "/api" ) ? state : "/" ;
23-
24- // url is a query parameter that is only set by the Vercel auth flow
25- // if it is set, and looks like a redirect to the device-auth flow,
26- // we redirect to the device-auth flow.
27- if ( typeof url === "string" && url . startsWith ( "https://auth.convex.dev" ) ) {
28- returnTo = url ;
29- } else if ( typeof path === "string" || typeof resource_id === "string" ) {
30- const key = typeof path === "string" ? "vercelPath" : "projectId" ;
31- const value = typeof path === "string" ? path : resource_id ;
32- returnTo = addQueryParam ( returnTo , key , value as string ) ;
33- }
34-
3522 if ( ! code ) {
3623 return res . status ( 400 ) . send ( "No code provided" ) ;
3724 }
@@ -47,7 +34,7 @@ export default async function handler(
4734 } ,
4835 } ) ;
4936
50- const { sealedSession } = authenticateResponse ;
37+ const { sealedSession, authenticationMethod } = authenticateResponse ;
5138
5239 // Store the session in a cookie
5340 const secure =
@@ -59,7 +46,23 @@ export default async function handler(
5946 `wos-session=${ sealedSession } ; Path=/; HttpOnly;${ secure } SameSite=Lax; Max-Age=${ 60 * 60 * 24 * 14 } ` ,
6047 ) ;
6148
62- // Use the information in `user` for further business logic.
49+ let returnTo = state && ! state . startsWith ( "/api" ) ? state : "/" ;
50+
51+ // url is a query parameter that is only set by the Vercel auth flow
52+ // if it is set, and looks like a redirect to the device-auth flow,
53+ // we redirect to the device-auth flow.
54+ if ( typeof url === "string" && url . startsWith ( "https://auth.convex.dev" ) ) {
55+ returnTo = url ;
56+ } else if ( typeof path === "string" || typeof resource_id === "string" ) {
57+ const key = typeof path === "string" ? "vercelPath" : "projectId" ;
58+ const value = typeof path === "string" ? path : resource_id ;
59+ returnTo = addQueryParam ( returnTo , key , value as string ) ;
60+ }
61+
62+ // @ts -expect-error VercelOAuth is a real authentication method
63+ if ( authenticationMethod === "VercelOAuth" ) {
64+ returnTo = addQueryParam ( returnTo , "vercelLogin" , "true" ) ;
65+ }
6366
6467 // Redirect the user to the homepage
6568 res . redirect ( returnTo ) ;
0 commit comments