WIP: DataSets Module
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { DataService } from '../services/data.service';
|
||||
import { AuthService } from './auth.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthGuard implements CanActivate {
|
||||
constructor(
|
||||
private data$: DataService,
|
||||
private auth$: AuthService,
|
||||
private router$: Router
|
||||
) {}
|
||||
canActivate(
|
||||
route: ActivatedRouteSnapshot,
|
||||
state: RouterStateSnapshot,
|
||||
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||
if (this.data$.currentUser) {
|
||||
if (this.auth$.user && this.auth$.user.googleCredentials) {
|
||||
return true;
|
||||
} else {
|
||||
this.router$.navigate(['']);
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { User } from '../models/user';
|
||||
import { User } from '../models/user.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthService {
|
||||
|
||||
apiToken: string | null = null;
|
||||
user: User | null = null;
|
||||
apiToken!: string;
|
||||
user!: User;
|
||||
|
||||
constructor(
|
||||
private http$: HttpClient
|
||||
@@ -35,7 +35,7 @@ export class AuthService {
|
||||
const header = new HttpHeaders().set('Content-type', 'application/json');
|
||||
this.http$.post<any>(`${environment.api.url}/auth/apiToken`, JSON.stringify(credentials), { headers: header }).subscribe({
|
||||
next: (data) => {
|
||||
if (this.user) { this.user.id = data.id }
|
||||
this.user.id = data.id;
|
||||
this.apiToken = data.token;
|
||||
resolve(data);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user