feat: redirect to same url on login/logout

This commit is contained in:
2023-08-09 15:58:36 +02:00
parent f066b4e5e4
commit 7a5f43d799
5 changed files with 46 additions and 16 deletions

View File

@@ -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, {