Skip to content

Instantly share code, notes, and snippets.

@blogcacanid
Created November 9, 2020 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blogcacanid/c920e806cac2321f146fa859ac4133f8 to your computer and use it in GitHub Desktop.
Save blogcacanid/c920e806cac2321f146fa859ac4133f8 to your computer and use it in GitHub Desktop.
auth.service.ts Authentication JWT Angular 9 Lumen 7
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