Skip to content

Commit 3890de7

Browse files
alakKevin CATHALYnsarrazin
authored
add alternative callback url (#766)
Co-authored-by: Kevin CATHALY <alakme@kevins-mbp.home> Co-authored-by: Nathan Sarrazin <sarrazin.nathan@gmail.com>
1 parent dddb85f commit 3890de7

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

.env

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,6 @@ EXPOSE_API=true
130130
# PUBLIC_APP_DATA_SHARING=1
131131
# PUBLIC_APP_DISCLAIMER=1
132132

133-
ENABLE_ASSISTANTS=false #set to true to enable assistants feature
133+
ENABLE_ASSISTANTS=false #set to true to enable assistants feature
134+
135+
ALTERNATIVE_REDIRECT_URLS=`[]` #valide alternative redirect URL for OAuth

.env.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,7 @@ PUBLIC_PLAUSIBLE_SCRIPT_URL="/js/script.js"
243243

244244
ENABLE_ASSISTANTS=true
245245
EXPOSE_API=true
246+
247+
ALTERNATIVE_REDIRECT_URLS=`[
248+
huggingchat://login/callback
249+
]`

src/routes/login/+page.server.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import { redirect } from "@sveltejs/kit";
22
import { getOIDCAuthorizationUrl } from "$lib/server/auth";
33
import { base } from "$app/paths";
4+
import { ALTERNATIVE_REDIRECT_URLS } from "$env/static/private";
45

56
export const actions = {
67
async default({ url, locals, request }) {
7-
// TODO: Handle errors if provider is not responding
88
const referer = request.headers.get("referer");
9+
let redirectURI = `${(referer ? new URL(referer) : url).origin}${base}/login/callback`;
10+
11+
// TODO: Handle errors if provider is not responding
12+
13+
if (url.searchParams.has("callback")) {
14+
const callback = url.searchParams.get("callback") || redirectURI;
15+
if (ALTERNATIVE_REDIRECT_URLS.includes(callback)) {
16+
redirectURI = callback;
17+
}
18+
}
19+
920
const authorizationUrl = await getOIDCAuthorizationUrl(
10-
{ redirectURI: `${(referer ? new URL(referer) : url).origin}${base}/login/callback` },
21+
{ redirectURI },
1122
{ sessionId: locals.sessionId }
1223
);
1324

0 commit comments

Comments
 (0)