feat: redirect to same url on login/logout
This commit is contained in:
@@ -1,18 +1,25 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { oauth2Client } from "@lib/auth.ts";
|
||||
import { sha256 } from "@lib/string.ts";
|
||||
import { setCookie } from "https://deno.land/std@0.197.0/http/cookie.ts";
|
||||
import { setCookie } from "$std/http/cookie.ts";
|
||||
|
||||
export const codeChallengeMap = new Map();
|
||||
export const codeChallengeMap = new Map<
|
||||
string,
|
||||
{ codeVerifier: string; redirect?: string }
|
||||
>();
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET() {
|
||||
async GET(req) {
|
||||
const url = new URL(req.url);
|
||||
|
||||
const { codeVerifier, uri } = await oauth2Client.code.getAuthorizationUri();
|
||||
|
||||
const codeChallenge = uri.searchParams.get("code_challenge");
|
||||
if (!codeChallenge) return new Response();
|
||||
|
||||
codeChallengeMap.set(codeChallenge, codeVerifier);
|
||||
codeChallengeMap.set(codeChallenge, {
|
||||
codeVerifier,
|
||||
redirect: decodeURIComponent(url.searchParams.get("redirect") || ""),
|
||||
});
|
||||
|
||||
const headers = new Headers();
|
||||
setCookie(headers, {
|
||||
|
||||
Reference in New Issue
Block a user