feat: make sure to save and restore the current url when logging in
This commit is contained in:
@@ -4,7 +4,7 @@ import { UmbAppContext } from './app.context.js';
|
||||
import { UmbServerConnection } from './server-connection.js';
|
||||
import { UmbAppAuthController } from './app-auth.controller.js';
|
||||
import type { UMB_AUTH_CONTEXT } from '@umbraco-cms/backoffice/auth';
|
||||
import { UmbAuthContext } from '@umbraco-cms/backoffice/auth';
|
||||
import { UMB_STORAGE_REDIRECT_URL, UmbAuthContext } from '@umbraco-cms/backoffice/auth';
|
||||
import { css, html, customElement, property } from '@umbraco-cms/backoffice/external/lit';
|
||||
import { UUIIconRegistryEssential } from '@umbraco-cms/backoffice/external/uui';
|
||||
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
|
||||
@@ -86,7 +86,14 @@ export class UmbAppElement extends UmbLitElement {
|
||||
: this.localize.term('errors_externalLoginFailed');
|
||||
|
||||
this.observe(this.#authContext.authorizationSignal, () => {
|
||||
history.replaceState(null, '', '');
|
||||
// Redirect to the saved state or root
|
||||
let currentRoute = '';
|
||||
const savedRoute = sessionStorage.getItem(UMB_STORAGE_REDIRECT_URL);
|
||||
if (savedRoute) {
|
||||
sessionStorage.removeItem(UMB_STORAGE_REDIRECT_URL);
|
||||
currentRoute = savedRoute.endsWith('logout') ? currentRoute : savedRoute;
|
||||
}
|
||||
history.replaceState(null, '', currentRoute);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { UmbBackofficeExtensionRegistry, ManifestAuthProvider } from '../extension-registry/index.js';
|
||||
import { UmbAuthFlow } from './auth-flow.js';
|
||||
import { UMB_AUTH_CONTEXT, UMB_STORAGE_TOKEN_RESPONSE_NAME } from './auth.context.token.js';
|
||||
import { UMB_AUTH_CONTEXT, UMB_STORAGE_REDIRECT_URL, UMB_STORAGE_TOKEN_RESPONSE_NAME } from './auth.context.token.js';
|
||||
import type { UmbOpenApiConfiguration } from './models/openApiConfiguration.js';
|
||||
import { OpenAPI } from '@umbraco-cms/backoffice/external/backend-api';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
@@ -106,6 +106,9 @@ export class UmbAuthContext extends UmbContextBase<UmbAuthContext> {
|
||||
) {
|
||||
const redirectUrl = await this.#authFlow.makeAuthorizationRequest(identityProvider, usernameHint);
|
||||
if (redirect) {
|
||||
// Save the current state
|
||||
sessionStorage.setItem(UMB_STORAGE_REDIRECT_URL, window.location.href);
|
||||
|
||||
location.href = redirectUrl;
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user