From b7aa7891e988ba2231ca9c3e58569c2a190622e5 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 12 Dec 2021 16:37:25 +0100 Subject: [PATCH] feat: redirect to calculated url everywhere --- src/helpers/redirectToProvider.ts | 11 ++++++++++- src/store/modules/config.js | 2 +- src/views/user/Login.vue | 4 +--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/helpers/redirectToProvider.ts b/src/helpers/redirectToProvider.ts index df67d3af..e7cd65e7 100644 --- a/src/helpers/redirectToProvider.ts +++ b/src/helpers/redirectToProvider.ts @@ -1,4 +1,5 @@ import {createRandomID} from '@/helpers/randomId' +import {parseURL} from 'ufo' interface Provider { name: string @@ -7,7 +8,15 @@ interface Provider { clientId: string } -export const redirectToProvider = (provider: Provider, redirectUrl: string) => { +export const redirectToProvider = (provider: Provider, redirectUrl: string = '') => { + + // We're not using the redirect url provided by the server to allow redirects when using the electron app. + // The implications are not quite clear yet hence the logic to pass in another redirect url still exists. + if (redirectUrl === '') { + const {host, protocol} = parseURL(window.location.href) + redirectUrl = `${protocol}//${host}/auth/openid/` + } + const state = createRandomID(24) localStorage.setItem('state', state) diff --git a/src/store/modules/config.js b/src/store/modules/config.js index 223e8098..82c2b20c 100644 --- a/src/store/modules/config.js +++ b/src/store/modules/config.js @@ -83,7 +83,7 @@ export default { ctx.state.auth.openidConnect.providers.length === 1 && window.location.pathname.startsWith('/login') // Kinda hacky, but prevents an endless loop. ) { - redirectToProvider(ctx.state.auth.openidConnect.providers[0], ctx.state.auth.openidConnect.redirectUrl) + redirectToProvider(ctx.state.auth.openidConnect.providers[0]) } }, }, diff --git a/src/views/user/Login.vue b/src/views/user/Login.vue index a720fdb1..daed587f 100644 --- a/src/views/user/Login.vue +++ b/src/views/user/Login.vue @@ -207,9 +207,7 @@ export default { }, redirectToProvider(provider) { - const {host, protocol} = parseURL(window.location.href) - const redirectUrl = `${protocol}//${host}/auth/openid/` - redirectToProvider(provider, redirectUrl) + redirectToProvider(provider) }, }, }