3.0 Beta 2
This commit is contained in:
17
src/app/guards/auth-needed-guard.spec.ts
Normal file
17
src/app/guards/auth-needed-guard.spec.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { CanActivateFn } from '@angular/router';
|
||||
|
||||
import { authNeededGuard } from './auth-needed-guard';
|
||||
|
||||
describe('authNeededGuard', () => {
|
||||
const executeGuard: CanActivateFn = (...guardParameters) =>
|
||||
TestBed.runInInjectionContext(() => authNeededGuard(...guardParameters));
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(executeGuard).toBeTruthy();
|
||||
});
|
||||
});
|
||||
24
src/app/guards/auth-needed-guard.ts
Normal file
24
src/app/guards/auth-needed-guard.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import {CanActivateFn, Router} from '@angular/router';
|
||||
import {inject} from '@angular/core';
|
||||
import {IndexedDB} from '../storage/indexed-db';
|
||||
import {Keyring} from '../storage/keyring';
|
||||
import {KeyValue} from '../storage/key-value';
|
||||
import {SessionManager} from '@chatenium/chatenium-sdk/services/sessionManager';
|
||||
|
||||
export const authNeededGuard: CanActivateFn = (route, state) => {
|
||||
const indexedDb = inject(IndexedDB)
|
||||
const keyring = inject(Keyring)
|
||||
const keyValue = inject(KeyValue)
|
||||
const router = inject(Router)
|
||||
|
||||
indexedDb.openDatabase().then(async () => {
|
||||
const sessionManager = new SessionManager(indexedDb.getApi(), keyring.getApi(), keyValue.getApi());
|
||||
const sessions = await sessionManager.loadSessions()
|
||||
|
||||
if (sessions.length == 0) {
|
||||
router.navigate(['/signin'])
|
||||
}
|
||||
})
|
||||
|
||||
return true;
|
||||
};
|
||||
17
src/app/guards/no-auth-guard.spec.ts
Normal file
17
src/app/guards/no-auth-guard.spec.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { CanActivateFn } from '@angular/router';
|
||||
|
||||
import { noAuthGuard } from './no-auth-guard';
|
||||
|
||||
describe('noAuthGuard', () => {
|
||||
const executeGuard: CanActivateFn = (...guardParameters) =>
|
||||
TestBed.runInInjectionContext(() => noAuthGuard(...guardParameters));
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(executeGuard).toBeTruthy();
|
||||
});
|
||||
});
|
||||
24
src/app/guards/no-auth-guard.ts
Normal file
24
src/app/guards/no-auth-guard.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import {CanActivateFn, Router} from '@angular/router';
|
||||
import {SessionManager} from '@chatenium/chatenium-sdk/services/sessionManager';
|
||||
import {inject} from '@angular/core';
|
||||
import {IndexedDB} from '../storage/indexed-db';
|
||||
import {Keyring} from '../storage/keyring';
|
||||
import {KeyValue} from '../storage/key-value';
|
||||
|
||||
export const noAuthGuard: CanActivateFn = async (route, state) => {
|
||||
const indexedDb = inject(IndexedDB)
|
||||
const keyring = inject(Keyring)
|
||||
const keyValue = inject(KeyValue)
|
||||
const router = inject(Router)
|
||||
|
||||
indexedDb.openDatabase().then(async () => {
|
||||
const sessionManager = new SessionManager(indexedDb.getApi(), keyring.getApi(), keyValue.getApi());
|
||||
const sessions = await sessionManager.loadSessions()
|
||||
|
||||
if (sessions.length != 0) {
|
||||
router.navigate(['/chat'])
|
||||
}
|
||||
})
|
||||
|
||||
return true;
|
||||
};
|
||||
Reference in New Issue
Block a user