Commit 28d05d0f by Nabil Sadki

FIX: routing

parent d5c1aa47
...@@ -17,7 +17,7 @@ const routes: Routes = [ ...@@ -17,7 +17,7 @@ const routes: Routes = [
loadChildren: './pages/offres/offre-details/offre-details.module#OffreDetailsPageModule', loadChildren: './pages/offres/offre-details/offre-details.module#OffreDetailsPageModule',
canActivate: [AuthGuardService] canActivate: [AuthGuardService]
}, },
{ path: 'login-help', loadChildren: './modals/compte/login-help/login-help.module#LoginHelpPageModule' }, { path: 'login-help', loadChildren: './modals/login-help/login-help.module#LoginHelpPageModule' },
]; ];
......
...@@ -99,8 +99,9 @@ export class AuthService { ...@@ -99,8 +99,9 @@ export class AuthService {
if (this.platform.is('cordova')) { if (this.platform.is('cordova')) {
this.httpAdv.post(Config.WORDPRESS_URL + 'wp-json/jwt-auth/v1/token', authData, {}).then( this.httpAdv.post(Config.WORDPRESS_URL + 'wp-json/jwt-auth/v1/token', authData, {}).then(
res => { res => {
console.log(res); const data = JSON.parse(res.data);
this.setUser(JSON.parse(res.data)); this.setUser(data);
this.setUserInfo(data.token);
this.authState.next(true); this.authState.next(true);
resolve(res); resolve(res);
}, },
...@@ -109,8 +110,42 @@ export class AuthService { ...@@ -109,8 +110,42 @@ export class AuthService {
} else { } else {
this.http.post(Config.WORDPRESS_URL + 'wp-json/jwt-auth/v1/token', authData).subscribe( this.http.post(Config.WORDPRESS_URL + 'wp-json/jwt-auth/v1/token', authData).subscribe(
res => { res => {
this.setUser(res); const data: any = res;
this.setUser(data);
this.setUserInfo(data.token);
this.authState.next(true); this.authState.next(true);
resolve(data);
},
err => reject(err)
);
}
});
}
setUserInfo(token) {
return new Promise<any>((resolve, reject) => {
if (this.platform.is('cordova')) {
let header: Headers = new Headers();
header.append('Authorization', 'Bearer ' + token);
this.httpAdv.get(
Config.WORDPRESS_URL + 'wp-json/wp/v2/users/me',
{},
{ headers: header }
).then(
res => {
console.log(res);
resolve(res);
},
err => reject(err)
);
} else {
this.http.get(
// Config.WORDPRESS_URL + 'wp-json/wp/v2/users/me',
Config.WORDPRESS_URL + 'wp-json/atapi/loggedinuser',
{ headers: { Authorization: 'Bearer ' + token } }
).subscribe(
res => {
console.log(res);
resolve(res); resolve(res);
}, },
err => reject(err) err => reject(err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment