Skip to content

Commit

Permalink
Merge pull request #55 from Service-Soft/54-add-ssr-support
Browse files Browse the repository at this point in the history
ssr support, package updates
  • Loading branch information
tim-fabian authored Dec 29, 2024
2 parents 957abf5 + e6d6b4b commit 7a00e3d
Show file tree
Hide file tree
Showing 15 changed files with 8,544 additions and 7,646 deletions.
16,029 changes: 8,455 additions & 7,574 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,31 @@
},
"private": true,
"dependencies": {
"@angular/animations": "~18.0.1",
"@angular/animations": "^18.0.1",
"@angular/cdk": "^18.0.1",
"@angular/common": "~18.0.1",
"@angular/compiler": "~18.0.1",
"@angular/core": "~18.0.1",
"@angular/forms": "~18.0.1",
"@angular/common": "^18.0.1",
"@angular/compiler": "^18.0.1",
"@angular/core": "^18.0.1",
"@angular/forms": "^18.0.1",
"@angular/material": "^18.0.1",
"@angular/platform-browser": "~18.0.1",
"@angular/platform-browser-dynamic": "~18.0.1",
"@angular/router": "~18.0.1",
"@angular/platform-browser": "^18.0.1",
"@angular/platform-browser-dynamic": "^18.0.1",
"@angular/router": "^18.0.1",
"@fortawesome/angular-fontawesome": "^0.15.0",
"@fortawesome/free-solid-svg-icons": "^6.7.2",
"rxjs": "~7.8.1",
"tslib": "^2.6.2",
"zone.js": "~0.14.6"
},
"devDependencies": {
"@angular-devkit/build-angular": "~18.0.2",
"@angular-devkit/build-angular": "^18.0.2",
"@angular/cli": "~18.0.2",
"@angular/compiler-cli": "~18.0.1",
"@angular/compiler-cli": "^18.0.1",
"@simplewebauthn/browser": "^10.0.0",
"@types/jasmine": "~5.1.4",
"@types/qrcode": "^1.5.5",
"concurrently": "^8.2.2",
"eslint-config-service-soft": "^1.5.0",
"eslint-config-service-soft": "^1.5.8",
"jasmine-core": "~5.1.2",
"karma": "~6.4.3",
"karma-chrome-launcher": "~3.2.0",
Expand All @@ -64,7 +66,7 @@
"npm-run-all": "^4.1.5",
"qrcode": "^1.5.3",
"ts-node": "^10.9.2",
"typescript": "~5.4.5",
"typescript": "~5.5",
"wait-on": "^7.2.0"
}
}
}
9 changes: 5 additions & 4 deletions projects/ngx-material-auth-showcase/src/app/routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable promise/prefer-await-to-then */

import { inject } from '@angular/core';
import { faHome, faLock, faUser } from '@fortawesome/free-solid-svg-icons';
import { JwtBelongsToGuard, JwtLoggedInGuard, JwtRoleGuard } from 'ngx-material-auth';
import { FooterRow, NavElementTypes, NavbarRow, NavUtilities, NavRoute } from 'ngx-material-navigation';

Expand All @@ -18,7 +19,7 @@ export const navbarRows: NavbarRow[] = [
path: '',
loadComponent: () => import('./pages/home/home.component').then(m => m.HomeComponent)
},
icon: 'fas fa-home',
icon: faHome,
name: 'Home',
collapse: 'never'
},
Expand All @@ -29,13 +30,13 @@ export const navbarRows: NavbarRow[] = [
path: 'login',
loadComponent: () => import('./pages/login/login.component').then(m => m.LoginComponent)
},
icon: 'fas fa-user',
icon: faUser,
name: 'Login',
collapse: 'sm'
},
{
type: NavElementTypes.MENU,
icon: 'fas fa-lock',
icon: faLock,
name: 'Restricted Routes',
collapse: 'sm',
elements: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable cspell/spellchecker */
/* eslint-disable sonar/no-duplicate-string */
import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { TestBed } from '@angular/core/testing';
import { MatDialogModule } from '@angular/material/dialog';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import jasmine from 'jasmine';
import { JwtInterceptor, NGX_AUTH_SERVICE, NGX_JWT_INTERCEPTOR_ALLOWED_DOMAINS } from 'ngx-material-auth';
import { firstValueFrom } from 'rxjs';

Expand Down Expand Up @@ -70,7 +68,7 @@ describe('CustomAuthService', () => {
password: 'stringstring'
});
}
catch (error) { }
catch { }
expect(service.authData).toBeUndefined();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpClient } from '@angular/common/http';
import { Injectable, NgZone } from '@angular/core';
import { Inject, Injectable, NgZone, PLATFORM_ID } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Router } from '@angular/router';
Expand Down Expand Up @@ -42,9 +42,11 @@ export class CustomAuthService extends JwtAuthService<CustomAuthData, Roles, Bas
snackBar: MatSnackBar,
ngZone: NgZone,
router: Router,
dialog: MatDialog
dialog: MatDialog,
@Inject(PLATFORM_ID)
platformId: Object
) {
super(http, snackBar, ngZone, router, dialog);
super(http, snackBar, ngZone, router, dialog, platformId);
}

async deleteAllBiometricCredentials(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-material-auth-showcase/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (environment.production) {
// eslint-disable-next-line unusedImports/no-unused-vars
function getBelongsToForRouteValue(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
const authService: CustomAuthService = inject(CustomAuthService);
if (!authService.authData?.userId) {
if (authService.authData?.userId) {
return false;
}
const allowedUserIds: string[] | undefined = route.data['allowedUserIds'] as string[] | undefined;
Expand Down
24 changes: 11 additions & 13 deletions projects/ngx-material-auth-showcase/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/app",
"types": []
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}
"compilerOptions": {
"outDir": "../../out-tsc/app",
"types": []
},
"extends": "../../tsconfig.json",
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": ["src/**/*.d.ts"]
}
28 changes: 13 additions & 15 deletions projects/ngx-material-auth-showcase/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": [
"jasmine"
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": ["jasmine"]
},
"extends": "../../tsconfig.json",
"files": [
"src/test.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
},
"files": [
"src/test.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
}
2 changes: 1 addition & 1 deletion projects/ngx-material-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-material-auth",
"version": "18.0.1",
"version": "18.0.2",
"license": "MIT",
"keywords": [
"angular",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class NgxMatAuthConfirmResetPasswordComponent<
form.resetForm();
await this.router.navigateByUrl(this.routeAfterReset);
}
catch (error) {
catch {
form.resetForm();
await this.router.navigateByUrl(this.routeAfterReset);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isPlatformBrowser } from '@angular/common';
import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpStatusCode } from '@angular/common/http';
import { Inject, Injectable } from '@angular/core';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { Observable, catchError, throwError } from 'rxjs';
Expand Down Expand Up @@ -57,7 +58,9 @@ export class HttpErrorInterceptor<
protected readonly router: Router,
@Inject(NGX_AUTH_SERVICE)
protected readonly authService: AuthServiceType,
protected readonly dialog: MatDialog
protected readonly dialog: MatDialog,
@Inject(PLATFORM_ID)
protected readonly platformId: Object
) { }

/**
Expand Down Expand Up @@ -129,6 +132,9 @@ export class HttpErrorInterceptor<
return error.message;
}
if (this.isCORSError(error)) {
if (!isPlatformBrowser(this.platformId)) {
return this.CORS_ERROR_MESSAGE;
}
if (!window.navigator.onLine) {
return this.NO_INTERNET_CONNECTION_ERROR_MESSAGE;
}
Expand Down
20 changes: 18 additions & 2 deletions projects/ngx-material-auth/src/services/jwt-auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isPlatformBrowser } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { InjectionToken, NgZone } from '@angular/core';
import { Inject, InjectionToken, NgZone, PLATFORM_ID } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Router } from '@angular/router';
Expand Down Expand Up @@ -220,6 +221,9 @@ export abstract class JwtAuthService<
}

set authData(value: AuthDataType | undefined) {
if (!isPlatformBrowser(this.platformId)) {
return;
}
value = this.transformAuthDataBeforeSetting(value);
localStorage.setItem(this.AUTH_DATA_KEY, JSON.stringify(value));
if (!value) {
Expand All @@ -237,6 +241,9 @@ export abstract class JwtAuthService<
* This is separated from the auth data because it's also needed when the user is logged out.
*/
get biometricCredentials(): BiometricCredentials[] {
if (!isPlatformBrowser(this.platformId)) {
return [];
}
const jsonString: string | null = localStorage.getItem(this.BIOMETRIC_CREDENTIALS_KEY);
if (!jsonString) {
return [];
Expand All @@ -245,6 +252,9 @@ export abstract class JwtAuthService<
}

set biometricCredentials(value: BiometricCredentials[] | undefined) {
if (!isPlatformBrowser(this.platformId)) {
return;
}
localStorage.setItem(this.BIOMETRIC_CREDENTIALS_KEY, JSON.stringify(value));
if (!value) {
localStorage.removeItem(this.BIOMETRIC_CREDENTIALS_KEY);
Expand All @@ -264,8 +274,14 @@ export abstract class JwtAuthService<
protected readonly snackbar: MatSnackBar,
protected readonly zone: NgZone,
protected readonly router: Router,
protected readonly dialog: MatDialog
protected readonly dialog: MatDialog,
@Inject(PLATFORM_ID)
protected readonly platformId: Object
) {
if (!isPlatformBrowser(platformId)) {
this.authDataSubject = new BehaviorSubject<AuthDataType | undefined>(undefined);
return;
}
const stringData: string | null = localStorage.getItem(this.AUTH_DATA_KEY);
const authData: AuthDataType | undefined = stringData ? JSON.parse(stringData) as AuthDataType : undefined;
this.authDataSubject = new BehaviorSubject(authData);
Expand Down
6 changes: 3 additions & 3 deletions projects/ngx-material-auth/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"outDir": "../../out-tsc/lib",
"types": []
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
],
"extends": "../../tsconfig.json"
}
8 changes: 4 additions & 4 deletions projects/ngx-material-auth/tsconfig.lib.prod.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.lib.json",
"angularCompilerOptions": {
"compilationMode": "partial"
},
"compilerOptions": {
"declarationMap": false
},
"angularCompilerOptions": {
"compilationMode": "partial"
}
"extends": "./tsconfig.lib.json"
}
10 changes: 3 additions & 7 deletions projects/ngx-material-auth/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": [
"jasmine"
]
"types": ["jasmine"]
},
"files": [
"src/test.ts"
],
"extends": "../../tsconfig.json",
"files": ["src/test.ts"],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
Expand Down

0 comments on commit 7a00e3d

Please sign in to comment.