Skip to content

Commit

Permalink
Merge pull request #306 from SharebookBR/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
raffacabofrio authored Jun 14, 2020
2 parents 6192f88 + 5364138 commit 039ad8f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "1.0.0",
"version": "v4.5.0",
"description": "It's just a getting started of front end sharebook application",
"main": "index.js",
"repository": {
Expand Down
46 changes: 25 additions & 21 deletions src/app/core/services/authentication/authentication.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Injectable, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { map } from 'rxjs/operators';
import { Router } from '@angular/router';
import * as moment from 'moment-timezone';
const moment = require('moment-timezone');

import { UserService } from '../user/user.service';

import { APP_CONFIG, AppConfig } from '../../../app-config.module';
const { version } = require('package.json');

@Injectable()
export class AuthenticationService {
Expand All @@ -19,26 +20,29 @@ export class AuthenticationService {
private _localStorageUserKey = 'shareBookUser';

login(email: string, password: string) {
return this.http
.post<any>(`${this.config.apiEndpoint}/Account/Login/`, {
email: email,
password: password,
const url = `${this.config.apiEndpoint}/Account/Login/`;
const body = {
email: email,
password: password,
};
const headers = new HttpHeaders({
'x-requested-with': 'web',
'Client-Version': version,
});
const options = { headers: headers };

return this.http.post<any>(url, body, options).pipe(
map((response) => {
// login successful if there's a jwt token in the response
if (response.success || response.value.authenticated) {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('shareBookUser', JSON.stringify(response.value));
this._user.setLoggedUser(response.value);
}

return response.value;
})
.pipe(
map((response) => {
// login successful if there's a jwt token in the response
if (response.success || response.value.authenticated) {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem(
'shareBookUser',
JSON.stringify(response.value)
);
this._user.setLoggedUser(response.value);
}

return response.value;
})
);
);
}

logout() {
Expand Down
11 changes: 4 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
"typeRoots": ["node_modules/@types"],
"lib": ["es2017", "dom"],
"resolveJsonModule": true,
"esModuleInterop": true
}
}

0 comments on commit 039ad8f

Please sign in to comment.