feat: redirect to calculated url everywhere
Some checks failed
continuous-integration/drone/pr Build is failing

This commit is contained in:
kolaente 2021-12-12 16:37:25 +01:00
parent e0941a4d82
commit c8aa4b2da6
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 12 additions and 5 deletions

View File

@ -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)

View File

@ -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])
}
},
},

View File

@ -220,9 +220,7 @@ export default {
},
redirectToProvider(provider) {
const {host, protocol} = parseURL(window.location.href)
const redirectUrl = `${protocol}//${host}/auth/openid/`
redirectToProvider(provider, redirectUrl)
redirectToProvider(provider)
},
},
}