Skip to content
Permalink
75402b3315
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
26 lines (21 sloc) 867 Bytes
export async function onRequestGet(context: RequestContext) {
const { env, request } = context;
const { host, protocol } = new URL(request.url);
let returnPath = "/";
const referer = request.headers.get("referer");
if (referer) returnPath = new URL(referer).pathname;
else {
const { searchParams } = new URL(context.request.url);
if (searchParams.get("type") === "mobile")
returnPath = "/api/auth/mobile/token";
}
const state = crypto.randomUUID().replaceAll("-", "");
await env.DATA.put(`state_${state}`, returnPath, { expirationTtl: 300 });
return Response.redirect(
`https://discord.com/oauth2/authorize?client_id=${
env.DISCORD_ID
}&redirect_uri=${encodeURIComponent(
`${protocol}//${host}/api/auth/session`,
)}&response_type=code&scope=identify%20email%20guilds.members.read&state=${state}`,
);
}