mirror of
https://github.com/TECHNOFAB11/svelte-oidc.git
synced 2025-12-11 23:50:06 +01:00
chore: lint
This commit is contained in:
parent
215a0a443f
commit
356f437331
1 changed files with 14 additions and 14 deletions
|
|
@ -81,46 +81,47 @@
|
||||||
const settings = {
|
const settings = {
|
||||||
authority: issuer,
|
authority: issuer,
|
||||||
client_id,
|
client_id,
|
||||||
// response_type: 'id_token token',
|
|
||||||
redirect_uri,
|
redirect_uri,
|
||||||
post_logout_redirect_uri,
|
post_logout_redirect_uri,
|
||||||
response_type: 'code',
|
response_type: 'code',
|
||||||
scope: 'openid profile email',
|
scope: 'openid profile email',
|
||||||
automaticSilentRenew: true,
|
automaticSilentRenew: true,
|
||||||
metadata
|
metadata,
|
||||||
};
|
};
|
||||||
|
|
||||||
const userManager = new UserManager(settings);
|
const userManager = new UserManager(settings);
|
||||||
userManager.events.addUserLoaded(function (user) {
|
userManager.events.addUserLoaded(function(user) {
|
||||||
isAuthenticated.set(true);
|
isAuthenticated.set(true);
|
||||||
accessToken.set(user.access_token);
|
accessToken.set(user.access_token);
|
||||||
idToken.set(user.id_token);
|
idToken.set(user.id_token);
|
||||||
userInfo.set(user.profile);
|
userInfo.set(user.profile);
|
||||||
});
|
});
|
||||||
|
|
||||||
userManager.events.addUserUnloaded(function () {
|
userManager.events.addUserUnloaded(function(e) {
|
||||||
isAuthenticated.set(false);
|
isAuthenticated.set(false);
|
||||||
idToken.set('');
|
idToken.set('');
|
||||||
accessToken.set('');
|
accessToken.set('');
|
||||||
userInfo.set({});
|
userInfo.set({});
|
||||||
});
|
});
|
||||||
|
|
||||||
userManager.events.addSilentRenewError(function (e) {
|
userManager.events.addSilentRenewError(function(e) {
|
||||||
authError.set(`silentRenewError: ${e.message}`);
|
authError.set(`SilentRenewError: ${e.message}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
let oidcPromise = Promise.resolve(userManager);
|
|
||||||
|
|
||||||
|
// userManager needs to be wrapped in a promise and the work
|
||||||
|
// needs to be done onMount to otherwise there is an
|
||||||
|
// Error: Function called outside component initialization
|
||||||
|
let oidcPromise = Promise.resolve(userManager);
|
||||||
setContext(OIDC_CONTEXT_CLIENT_PROMISE, oidcPromise);
|
setContext(OIDC_CONTEXT_CLIENT_PROMISE, oidcPromise);
|
||||||
|
|
||||||
|
// Not all browsers support this, please program defensively!
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
async function handleOnMount() {
|
async function handleOnMount() {
|
||||||
// on run onMount after oidc
|
// on run onMount after oidc
|
||||||
const oidc = await oidcPromise;
|
const oidc = await oidcPromise;
|
||||||
|
|
||||||
// Not all browsers support this, please program defensively!
|
|
||||||
const params = new URLSearchParams(window.location.search);
|
|
||||||
|
|
||||||
// Check if something went wrong during login redirect
|
// Check if something went wrong during login redirect
|
||||||
// and extract the error message
|
// and extract the error message
|
||||||
if (params.has('error')) {
|
if (params.has('error')) {
|
||||||
|
|
@ -131,13 +132,13 @@
|
||||||
if (params.has('code')) {
|
if (params.has('code')) {
|
||||||
// handle the callback
|
// handle the callback
|
||||||
const response = await oidc.signinCallback();
|
const response = await oidc.signinCallback();
|
||||||
let state = (response && response.state) || {}
|
let state = (response && response.state) || {};
|
||||||
// Can be smart here and redirect to original path instead of root
|
// Can be smart here and redirect to original path instead of root
|
||||||
const url = state && state.targetUrl ? state.targetUrl : window.location.pathname;
|
const url = state && state.targetUrl ? state.targetUrl : window.location.pathname;
|
||||||
state = { ...state, isRedirectCallback: true };
|
state = { ...state, isRedirectCallback: true };
|
||||||
|
|
||||||
// redirect to the last page we were on when login was configured if it was passed.
|
// redirect to the last page we were on when login was configured if it was passed.
|
||||||
history.replaceState(state, "", url);
|
history.replaceState(state, '', url);
|
||||||
// location.href = url;
|
// location.href = url;
|
||||||
// clear errors on login.
|
// clear errors on login.
|
||||||
authError.set(null);
|
authError.set(null);
|
||||||
|
|
@ -150,5 +151,4 @@
|
||||||
onDestroy(handleOnDestroy);
|
onDestroy(handleOnDestroy);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<slot />
|
||||||
<slot></slot>
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue