Skip to content

Commit

Permalink
Fazendo o app aproveitar o usuario logado na tela inicial
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscolopes committed May 5, 2018
1 parent fc57713 commit d406c75
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/pages/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ export class HomePage {
this.menu.swipeEnable(true);
}

ionViewDidEnter() {
this.auth.refreshToken()
.subscribe(response => {
this.auth.successfulLogin(response.headers.get('Authorization'));
this.navCtrl.setRoot('CategoriasPage');
},
error => { });
}

login() {
this.auth.authenticate(this.creds)
.subscribe(response => {
Expand Down
10 changes: 10 additions & 0 deletions src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export class AuthService {
});
}

refreshToken() {
return this.http.post(
`${API_CONFIG.baseUrl}/auth/refresh_token`,
{},
{
observe: 'response',
responseType: 'text'
});
}

successfulLogin(authorizationValue: string) {
let tok = authorizationValue.substring(7);
let user: LocalUser = {
Expand Down

0 comments on commit d406c75

Please sign in to comment.