From d587360f4bc0e3a3f9246083cf642bbe1f4a62c7 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 21 May 2023 11:54:38 -0400 Subject: [PATCH] fix: Show desktop sign-in errors within the app --- server/middlewares/passport.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/middlewares/passport.ts b/server/middlewares/passport.ts index 849603f71..0b207ffe3 100644 --- a/server/middlewares/passport.ts +++ b/server/middlewares/passport.ts @@ -1,6 +1,7 @@ import passport from "@outlinewiki/koa-passport"; import { Context } from "koa"; import { InternalOAuthError } from "passport-oauth2"; +import { Client } from "@shared/types"; import env from "@server/env"; import { AuthenticationError } from "@server/errors"; import Logger from "@server/logging/Logger"; @@ -32,11 +33,13 @@ export default function createMiddleware(providerName: string) { // same domain or subdomain that they originated from (found in state). // get original host - const state = ctx.cookies.get("state"); - const host = state ? parseState(state).host : ctx.hostname; + const stateString = ctx.cookies.get("state"); + const state = stateString ? parseState(stateString) : undefined; + const host = state?.host ?? ctx.hostname; // form a URL object with the err.redirectUrl and replace the host - const reqProtocol = ctx.protocol; + const reqProtocol = + state?.client === Client.Desktop ? "outline" : ctx.protocol; const requestHost = ctx.get("host"); const url = new URL( `${reqProtocol}://${requestHost}${redirectUrl}`