Created
November 9, 2020 21:43
-
-
Save blogcacanid/c920e806cac2321f146fa859ac4133f8 to your computer and use it in GitHub Desktop.
auth.service.ts Authentication JWT Angular 9 Lumen 7
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 { HttpClient, HttpHeaders } from '@angular/common/http'; | |
import { Observable } from 'rxjs'; | |
// for Lumen 7 back-end | |
const AUTH_API = 'http://localhost:8000/api/auth/'; | |
// for Node.js back-end | |
// const AUTH_API = 'http://localhost:9090/api/auth/'; | |
const httpOptions = { | |
headers: new HttpHeaders({ 'Content-Type': 'application/json' }) | |
}; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class AuthService { | |
constructor(private http: HttpClient) { } | |
login(credentials): Observable<any> { | |
return this.http.post(AUTH_API + 'login', { | |
username: credentials.username, | |
password: credentials.password | |
}, httpOptions); | |
} | |
register(user): Observable<any> { | |
return this.http.post(AUTH_API + 'register', { | |
username: user.username, | |
email: user.email, | |
password: user.password | |
}, httpOptions); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment