Skip to content

Commit

Permalink
feat(com-pwa): check signed in
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm authored and AliMD committed Apr 26, 2023
1 parent 25c77ae commit 1fa6db7
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions uniquely/com-pwa/src/ui/alwatr-pwa.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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`<alwatr-page-home unresolved>...</alwatr-page-home>`;
Expand All @@ -52,10 +59,7 @@ class AlwatrPwa extends AlwatrPwaElement {
import('./page/order.js');
topAppBarContextProvider.setValue({headlineKey: 'loading'});
const orderId = routeContext.sectionList[1] || 'new';
return html`<alwatr-page-order
.orderId=${orderId}
unresolved
>...</alwatr-page-order>`;
return html`<alwatr-page-order .orderId=${orderId} unresolved>...</alwatr-page-order>`;
}

protected _renderPageSignIn(): unknown {
Expand All @@ -76,4 +80,10 @@ class AlwatrPwa extends AlwatrPwaElement {
protected override _navigationBarTemplate(): unknown {
return html`<alwatr-app-footer></alwatr-app-footer>`;
}

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']});
}
}

0 comments on commit 1fa6db7

Please sign in to comment.