From 1fa6db78f6fe91b1663d1e48f27ee778e06879ea Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Mon, 24 Apr 2023 21:40:26 +0330 Subject: [PATCH] feat(com-pwa): check signed in --- uniquely/com-pwa/src/ui/alwatr-pwa.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/uniquely/com-pwa/src/ui/alwatr-pwa.ts b/uniquely/com-pwa/src/ui/alwatr-pwa.ts index eb3d69e07..918f8e86b 100644 --- a/uniquely/com-pwa/src/ui/alwatr-pwa.ts +++ b/uniquely/com-pwa/src/ui/alwatr-pwa.ts @@ -1,7 +1,7 @@ import {html, customElement, nothing} from '@alwatr/element'; import '@alwatr/font/vazirmatn.css'; import {AlwatrPwaElement} from '@alwatr/pwa-helper/pwa-element.js'; -import {redirect, type RouteContext, type RoutesConfig} from '@alwatr/router'; +import {redirect, routeContextConsumer, type RouteContext, type RoutesConfig} from '@alwatr/router'; import '@alwatr/ui-kit/style/mobile-only.css'; import '@alwatr/ui-kit/style/theme/color.css'; import '@alwatr/ui-kit/style/theme/palette-270.css'; @@ -32,6 +32,13 @@ class AlwatrPwa extends AlwatrPwaElement { }, }; + override connectedCallback(): void { + super.connectedCallback(); + routeContextConsumer.subscribe((routerContext) => { + this._checkSignedIn(routerContext.sectionList[0] + ''); + }); + } + protected _renderPageHome(): unknown { import('./page/home.js'); return html`...`; @@ -52,10 +59,7 @@ class AlwatrPwa extends AlwatrPwaElement { import('./page/order.js'); topAppBarContextProvider.setValue({headlineKey: 'loading'}); const orderId = routeContext.sectionList[1] || 'new'; - return html`...`; + return html`...`; } protected _renderPageSignIn(): unknown { @@ -76,4 +80,10 @@ class AlwatrPwa extends AlwatrPwaElement { protected override _navigationBarTemplate(): unknown { return html``; } + + protected _checkSignedIn(route: string): void { + this._logger.logMethodArgs?.('_checkSignedIn', {route}); + if (localStorage.getItem('user-token') != null || route === 'sign-in' || route === 's' || route === '') return; + redirect({sectionList: ['sign-in']}); + } }