Fixes ssr bugs

parent a53c1628
Pipeline #18238 passed with stages
in 10 minutes and 28 seconds
import { isPlatformServer } from '@angular/common';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { AbstractQuestionGroup } from 'arsnova-click-v2-types/src/questions/questiongroup_abstract';
import { Observable } from 'rxjs';
import { Observable, of } from 'rxjs';
import { DB_NAME, DB_TABLE, STORAGE_KEY } from '../../shared/enums';
import { IndexedDbService } from './indexed.db.service';
......@@ -25,6 +25,10 @@ export class StorageService {
}
public create(table: DB_TABLE, key: string | STORAGE_KEY, value: any): Observable<any> {
if (isPlatformServer(this.platformId)) {
return of(null);
}
if (value instanceof AbstractQuestionGroup) {
value = value.serialize();
}
......@@ -36,20 +40,36 @@ export class StorageService {
}
public read(table: DB_TABLE, key: string | STORAGE_KEY): Observable<any> {
if (isPlatformServer(this.platformId)) {
return of(null);
}
return this.indexedDbService.get(table, this.formatKey(key));
}
public delete(table: DB_TABLE, key: string | STORAGE_KEY): Observable<any> {
if (isPlatformServer(this.platformId)) {
return of(null);
}
return this.indexedDbService.remove(table, this.formatKey(key));
}
public async getAllQuiznames(): Promise<Array<string>> {
if (isPlatformServer(this.platformId)) {
return of(null).toPromise();
}
return (
await this.indexedDbService.all(DB_TABLE.QUIZ).toPromise()
).map(value => value.id);
}
public getAll(table: DB_TABLE): Observable<any> {
if (isPlatformServer(this.platformId)) {
return of(null);
}
return this.indexedDbService.all(table);
}
......
import { EventEmitter, Injectable } from '@angular/core';
import { isPlatformServer } from '@angular/common';
import { EventEmitter, Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { JwtHelperService } from '@auth0/angular-jwt';
import { ILoginSerialized } from 'arsnova-click-v2-types/src/common';
import { DB_TABLE, STORAGE_KEY, USER_AUTHORIZATION } from '../../shared/enums';
......@@ -57,11 +58,21 @@ export class UserService {
return this._staticLoginToken;
}
constructor(private authorizeApiService: AuthorizeApiService, private storageService: StorageService, private jwtHelper: JwtHelperService) {
constructor(
@Inject(PLATFORM_ID) private platformId: Object,
private authorizeApiService: AuthorizeApiService,
private storageService: StorageService,
private jwtHelper: JwtHelperService,
) {
}
public loadConfig(): Promise<boolean> {
return new Promise<boolean>(async resolve => {
if (isPlatformServer(this.platformId)) {
resolve(true);
return;
}
const tokens = await this.storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.TOKEN).toPromise();
if (!tokens) {
......
import { StorageService } from '../app/service/storage/storage.service';
import { DB_TABLE, STORAGE_KEY } from '../app/shared/enums';
export function jwtOptionsFactory(storageService): any {
export function jwtOptionsFactory(storageService: StorageService): any {
return {
tokenGetter: async () => {
const tokens = await storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.TOKEN).toPromise();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment