Bläddra i källkod

fix(mobile): restore remembered login from WeChat link

彭峰 7 timmar sedan
förälder
incheckning
6dce8e69c5
1 ändrade filer med 11 tillägg och 0 borttagningar
  1. 11 0
      projects/xiaoshu-mobile/src/app/features/auth/login-page.component.ts

+ 11 - 0
projects/xiaoshu-mobile/src/app/features/auth/login-page.component.ts

@@ -44,6 +44,17 @@ export class LoginPageComponent implements OnInit, OnDestroy {
   private readonly route = inject(ActivatedRoute);
 
   ngOnInit(): void {
+    // WeChat links may reopen the login URL directly. The session service
+    // restores the device's persisted session before this page initializes,
+    // so skip the form when that session is still present.
+    if (this.session.isLoggedIn()) {
+      const requestedReturnUrl = this.route.snapshot.queryParamMap.get('returnUrl');
+      const returnUrl = requestedReturnUrl?.startsWith('/') && !requestedReturnUrl.startsWith('//')
+        ? requestedReturnUrl
+        : '/pages/home/index';
+      void this.router.navigateByUrl(returnUrl, { replaceUrl: true });
+      return;
+    }
     if(this.route.snapshot.queryParamMap.get('passwordChanged')==='1')this.sessionMessage.set('密码已修改,请使用新密码重新登录');
     if (this.route.snapshot.queryParamMap.get('expired') === '1') {
       this.sessionMessage.set('登录状态已过期,请重新登录后继续学习');