feat: redirect to calculated url everywhere

This commit is contained in:
kolaente 2021-12-12 16:37:25 +01:00 committed by Gitea
parent ccaed029f2
commit b7aa7891e9
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

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