问题描述 投票:0回答:1
我对 auth0 还很陌生。我有一个 Angular 应用程序,其中有几个需要身份验证的页面。此时用户到达首页,然后被重定向到auth0认证页面进行登录。连接成功后,用户被重定向到/app页面。 这一切都运作良好。但是,一旦我在此应用程序页面中添加一个调用 auth0 logout() 函数的按钮,行为就会发生变化。这次,一旦用户登录,他们就会被重定向到 /app 页面,然后立即重定向到主页。就好像用户立即注销一样。然而,从 auth0 中的 isAuthenticated$ 变量来看,用户似乎没有注销。

我希望断开连接按钮不再导致此问题。 起初我以为用户直接注销了,登录和应用这两个页面没有共享同一个 auth0 会话。但是,他们确实使用相同的服务,该服务是单独声明的,正如我所说,用户似乎没有注销。这可以解释重定向到起始页的情况,但不能解释用户似乎仍然处于登录状态的事实。因此,我想在我的 auth0 应用程序页面上设置一个 auth0 注销逻辑,这样不会产生错误。

非常感谢您的帮助。

angular debugging auth0 logout
1个回答
0
投票
您是否指定了

returnTo

 参数?这是我在一个示例中使用的内容:

import { Component, Inject } from '@angular/core'; import { AuthService } from '@auth0/auth0-angular'; import { AsyncPipe, DOCUMENT } from '@angular/common'; @Component({ standalone: true, selector: 'app-home', imports: [AsyncPipe], templateUrl: './home.component.html', styleUrl: './home.component.css' }) export class HomeComponent { constructor(public auth: AuthService, @Inject(DOCUMENT) private doc: Document) { } login(): void { this.auth.loginWithRedirect(); } logout(): void { this.auth.logout({ logoutParams: { returnTo: this.doc.location.origin } }); } }
    
© www.soinside.com 2019 - 2024. All rights reserved.