Last active
July 19, 2022 11:38
-
-
Save avatsaev/0a4027acba81651f7c4e2d1043b84285 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import {Angular2TokenService} from "angular2-token"; | |
import {Subject, Observable} from "rxjs"; | |
import {Response} from "@angular/http"; | |
@Injectable() | |
export class AuthService { | |
userSignedIn$:Subject<boolean> = new Subject(); | |
constructor(public authService:Angular2TokenService) { | |
this.authService.validateToken().subscribe( | |
res => res.status == 200 ? this.userSignedIn$.next(res.json().success) : this.userSignedIn$.next(false) | |
) | |
} | |
logOutUser():Observable<Response>{ | |
return this.authService.signOut().map( | |
res => { | |
this.userSignedIn$.next(false); | |
return res; | |
} | |
); | |
} | |
registerUser(signUpData: {email:string, password:string, passwordConfirmation:string}):Observable<Response>{ | |
return this.authService.registerAccount(signUpData).map( | |
res => { | |
this.userSignedIn$.next(true); | |
return res | |
} | |
); | |
} | |
logInUser(signInData: {email:string, password:string}):Observable<Response>{ | |
return this.authService.signIn(signInData).map( | |
res => { | |
this.userSignedIn$.next(true); | |
return res | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment