refactor: check keycloak init
This commit is contained in:
parent
a096a2520b
commit
506a65f27a
1 changed files with 13 additions and 8 deletions
|
|
@ -2,15 +2,20 @@ import Keycloak from 'keycloak-js'
|
|||
|
||||
const keycloak = new Keycloak('/keycloak.json')
|
||||
|
||||
export async function login(cb?: (...args: any[]) => void) {
|
||||
const auth = await keycloak
|
||||
.init({
|
||||
onLoad: 'login-required',
|
||||
responseMode: 'query',
|
||||
checkLoginIframe: false,
|
||||
})
|
||||
.catch((e) => console.dir(e))
|
||||
let init = false
|
||||
|
||||
export async function login(cb?: (...args: any[]) => void) {
|
||||
const auth = !init
|
||||
? await keycloak
|
||||
.init({
|
||||
onLoad: 'login-required',
|
||||
responseMode: 'query',
|
||||
checkLoginIframe: false,
|
||||
})
|
||||
.catch((e) => console.dir(e))
|
||||
: await keycloak.login().catch((e) => console.dir(e))
|
||||
|
||||
if (auth) init = true
|
||||
if (auth && cb) cb()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue