-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] saving logged user to localStorage #5
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea quite a bit. If you can fix up the expiration check when loading an access token from local storage and roll back your minor formatting changes with the braces { this } vs. {this} then we'll be good to go.
|
||
this.token = localStorage.getItem('access_token'); | ||
if (this.token) { | ||
this.authenticated = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there is a problem here, though I like what you are doing in general. I don't think you can set this.authenticated
to true unless a) there is an expires value in local storage and b) that value has not passed already. We can't set auth to true if there's no expires value, and we can't set it to true if that expires value has already expired. If you can fix that up, I'll accept the new merge request.
@@ -122,15 +135,15 @@ export class AuthService { | |||
} | |||
|
|||
public getSession() { | |||
return {authenticated: this.authenticated, token: this.token, expires: this.expires}; | |||
return { authenticated: this.authenticated, token: this.token, expires: this.expires }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer that the formatting stay consistent with the rest of the code; no spaces inside the braces.
import {Injectable, EventEmitter} from "@angular/core"; | ||
import {WindowService} from "./window.service"; | ||
import {Http, Headers} from "@angular/http"; | ||
import { Injectable, EventEmitter } from "@angular/core"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer that the formatting stay consistent with the rest of the code; no spaces inside the braces.
} | ||
|
||
private fetchUserInfo() { | ||
if (this.token != null) { | ||
var headers = new Headers(); | ||
headers.append('Authorization', `Bearer ${this.token}`); | ||
//noinspection TypeScriptUnresolvedFunction | ||
this.http.get(this.oAuthUserUrl, {headers: headers}) | ||
this.http.get(this.oAuthUserUrl, { headers: headers }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer that the formatting stay consistent with the rest of the code; no spaces inside the braces.
No description provided.