fix redirect

This commit is contained in:
split / May 2024-07-10 22:09:11 -07:00
parent 886f06dcd8
commit 3199cfd8dd
Signed by: split
GPG key ID: C325C61F0BF517C0
2 changed files with 6 additions and 6 deletions

View file

@ -12,7 +12,7 @@ const userInfoCache = new Map<string, User>()
* @description Launch an OAuth2 login request for this request. * @description Launch an OAuth2 login request for this request.
* @param req Request to launch the login for; required to obtain the Host header. * @param req Request to launch the login for; required to obtain the Host header.
*/ */
export function launchLogin(req: Request) { export function launchLogin(url: string) {
// Create a state to be used in the OAuth2 authorization request // Create a state to be used in the OAuth2 authorization request
const state = crypto.randomUUID() const state = crypto.randomUUID()
@ -20,7 +20,7 @@ export function launchLogin(req: Request) {
const searchParams = new URLSearchParams({ const searchParams = new URLSearchParams({
response_type: "code", response_type: "code",
client_id: configuration.oauth2.client.id, client_id: configuration.oauth2.client.id,
redirect_uri: req.url, redirect_uri: url,
scope: "openid profile", scope: "openid profile",
state state
}) })
@ -41,7 +41,7 @@ export function launchLogin(req: Request) {
() => states.delete(state), () => states.delete(state),
2*60*1000 2*60*1000
), ),
redirect_uri: req.url redirect_uri: url
} }
) )

View file

@ -3,13 +3,13 @@ import configuration from "$lib/configuration.js";
import { fail } from "@sveltejs/kit"; import { fail } from "@sveltejs/kit";
import { avatarDirectory, renderSizes, setNewAvatar } from "$lib/avatars.js"; import { avatarDirectory, renderSizes, setNewAvatar } from "$lib/avatars.js";
import { join } from "path"; import { join } from "path";
export async function load({ request, parent }) { export async function load({ request, parent, url }) {
const { user } = await parent(); const { user } = await parent();
if (!user) if (!user)
launchLogin(request) launchLogin(url.toString())
return { return {
url: request.url, url: url.toString(),
allowedImageTypes: configuration.allowed_types, allowedImageTypes: configuration.allowed_types,
renderSizes renderSizes
} }