|
|
@@ -1,4 +1,4 @@
|
|
|
-//import { environment } from 'src/environments/environment';
|
|
|
+import { environment } from 'src/environments/environment';
|
|
|
import { User } from './../models/userResponse';
|
|
|
import { Token, payloadToken } from './../models/token';
|
|
|
import { Injectable } from '@angular/core';
|
|
|
@@ -18,7 +18,7 @@ import * as jwt_decode from 'jwt-decode';
|
|
|
export class AuthService {
|
|
|
|
|
|
//url api
|
|
|
- // private apiUrl = environment.apiUrl
|
|
|
+ private apiUrl = environment.apiUrl
|
|
|
|
|
|
private currentUserSubject: BehaviorSubject<User> = new BehaviorSubject<User>(null);
|
|
|
public currentUser: Observable<User> = this.currentUserSubject.asObservable();
|
|
|
@@ -62,9 +62,9 @@ export class AuthService {
|
|
|
// login get token on login
|
|
|
signIn(credentials): Observable<Token> {
|
|
|
//debugger;
|
|
|
- // console.log("url ========",this.apiUrl);
|
|
|
+ console.log("url ========",this.apiUrl);
|
|
|
|
|
|
- return this.http.post<Token>(`https://api-preprod.foodgame.fr/api/auth/login`, credentials)
|
|
|
+ return this.http.post<Token>(`${this.apiUrl}/api/auth/login`, credentials)
|
|
|
.pipe(map(token => {
|
|
|
// store jwt token in local storage
|
|
|
localStorage.setItem('token', JSON.stringify(token));
|
|
|
@@ -98,9 +98,9 @@ export class AuthService {
|
|
|
// login get token on login admin
|
|
|
signInAdmin(credentials): Observable<Token> {
|
|
|
//debugger;
|
|
|
- //console.log("url ========",this.apiUrl);
|
|
|
+ console.log("url ========",this.apiUrl);
|
|
|
|
|
|
- return this.http.post<Token>(`https://api-preprod.foodgame.fr/api/auth/admin`, credentials)
|
|
|
+ return this.http.post<Token>(`${this.apiUrl}/api/auth/admin`, credentials)
|
|
|
.pipe(map(token => {
|
|
|
// store jwt token in local storage
|
|
|
localStorage.setItem('token', JSON.stringify(token));
|
|
|
@@ -113,11 +113,8 @@ export class AuthService {
|
|
|
|
|
|
// iscription get token on login
|
|
|
signUP(data): Observable<Token> {
|
|
|
- debugger;
|
|
|
- // console.log("url ========",this.apiUrl);
|
|
|
-
|
|
|
|
|
|
- return this.http.post<Token>(`https://api-preprod.foodgame.fr/api/auth/signup`, data)
|
|
|
+ return this.http.post<Token>(`${this.apiUrl}/api/auth/signup`, data)
|
|
|
.pipe(map(token => {
|
|
|
// store jwt token in local storage
|
|
|
localStorage.setItem('token', JSON.stringify(token));
|
|
|
@@ -130,13 +127,13 @@ export class AuthService {
|
|
|
|
|
|
// mot de passe oublie
|
|
|
lostPassword(email): Observable<any> {
|
|
|
- return this.http.put<any>(`https://api-preprod.foodgame.fr/api/auth/forgot-password`, email)
|
|
|
+ return this.http.put<any>(`${this.apiUrl}/api/auth/forgot-password`, email)
|
|
|
}
|
|
|
|
|
|
|
|
|
// réinitialiser mot de passe
|
|
|
resetPassword(data): Observable<any> {
|
|
|
- return this.http.put<any>(`https://api-preprod.foodgame.fr/api/auth/reset-password`, data)
|
|
|
+ return this.http.put<any>(`${this.apiUrl}/api/auth/reset-password`, data)
|
|
|
}
|
|
|
|
|
|
// isLoggedIn
|
|
|
@@ -167,18 +164,6 @@ resetPassword(data): Observable<any> {
|
|
|
}
|
|
|
|
|
|
getUserInfo(): Observable<User> {
|
|
|
-<<<<<<< HEAD
|
|
|
-
|
|
|
- let decodedToken : payloadToken = jwt_decode(this.tokenSubject.value.token);
|
|
|
- return this.http.get<User>(`https://api-preprod.foodgame.fr/api/users/${decodedToken.userId}`)
|
|
|
- .pipe(map(user => {
|
|
|
- // store user info in local storage
|
|
|
- localStorage.setItem('user', JSON.stringify(user));
|
|
|
- this.user_infoSubject.next(user);
|
|
|
- return user;
|
|
|
- }));
|
|
|
-
|
|
|
-=======
|
|
|
let token = this.tokenSubject.value.token;
|
|
|
if (token) {
|
|
|
// User is authenticated locally
|
|
|
@@ -202,7 +187,6 @@ resetPassword(data): Observable<any> {
|
|
|
})
|
|
|
);
|
|
|
}
|
|
|
->>>>>>> test
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -216,4 +200,4 @@ resetPassword(data): Observable<any> {
|
|
|
}
|
|
|
|
|
|
|
|
|
-}
|
|
|
+}
|