diff --git a/functions/api/auth/mobile/token.ts b/functions/api/auth/mobile/token.ts index 027d86d..0fa7967 100644 --- a/functions/api/auth/mobile/token.ts +++ b/functions/api/auth/mobile/token.ts @@ -42,6 +42,13 @@ export async function onRequestGet(context: RequestContext) { "", ); + const oauthCredentials = await context.env.DATA.get( + `oauthcredentials_${currentUser.id}`, + { type: "json" }, + ); + + if (!oauthCredentials) return jsonError("No credentials found for you", 500); + await context.env.DATA.put( `auth_${btoa( String.fromCharCode( @@ -58,7 +65,7 @@ export async function onRequestGet(context: RequestContext) { .replaceAll("=", "")}`, JSON.stringify(currentUser), { - expirationTtl: currentUser.expires_in + 1209600, + expirationTtl: 2419200, }, ); @@ -66,7 +73,7 @@ export async function onRequestGet(context: RequestContext) { JSON.stringify({ email: currentUser.email, email_verified: true, - exp: Math.floor(Date.now() / 1000) + currentUser.expires_in, + exp: Math.floor(Date.now() / 1000) + 2419200, iat: Math.floor(Date.now() / 1000), iss: "https://carcrushers.cc/auth/mobile/token", jti: tokenId, @@ -107,17 +114,20 @@ export async function onRequestGet(context: RequestContext) { .replaceAll("/", "_") .replaceAll("=", ""); - return new Response(` + return new Response( + `
You were logged in successfully. If this page does not close in a few seconds, please click done.
-`, { - headers: { - "content-type": "text/html", - location: `com.carcrushers.app://login-callback?token=${header}.${claimSet}.${encodedSignature}` +`, + { + headers: { + "content-type": "text/html", + location: `com.carcrushers.app://login-callback?token=${header}.${claimSet}.${encodedSignature}`, + }, + status: 302, }, - status: 302, - }); + ); } diff --git a/functions/api/auth/session.ts b/functions/api/auth/session.ts index 0301cc5..3e5e202 100644 --- a/functions/api/auth/session.ts +++ b/functions/api/auth/session.ts @@ -130,14 +130,14 @@ export async function onRequestGet(context: RequestContext) { const tokenHash = await generateTokenHash(authToken); await context.env.DATA.put(`auth_${tokenHash}`, JSON.stringify(userData), { - expirationTtl: tokenData.expires_in, + expirationTtl: 2419200, }); await context.env.DATA.put( `oauthcredentials_${userData.id}`, JSON.stringify(oauthData), { - expirationTtl: 1209600000, + expirationTtl: 1209600, }, );