Skip to content
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

Access token is not stored after login #55

Closed
aloxiao opened this issue Nov 3, 2017 · 10 comments
Closed

Access token is not stored after login #55

aloxiao opened this issue Nov 3, 2017 · 10 comments

Comments

@aloxiao
Copy link

aloxiao commented Nov 3, 2017

Hi,
I make it docs/articles/auth-guard.md.
At app-routing.module.ts

{
path: 'pages',
canActivate: [AuthGuard], //add line
loadChildren: 'app/pages/pages.module#PagesModule' },
}
...
Result cosole.log(result); //line 53 in login.component.js
NbAuthResult {success: true, response: HttpResponse, redirect: "/", errors: Array(1), messages: Array(1), …}

However, page not nagivator to "pages/dashboard". If i hidden line canActivate then I can access dashboard but deafault load login.
Where is error?
Pleases help me!
(My english is not so good).

@nnixaa
Copy link
Collaborator

nnixaa commented Nov 4, 2017

Hello @aloxiao, we would need much more details on this, are you using ngx-admin? Which provider are you using? Could you provide a reproducible example?

@aloxiao
Copy link
Author

aloxiao commented Nov 6, 2017

Dear @nnixaa ,
I am begin Github and Angular 4, i can not upload Github.
I give link my project (Note: i am not user email login, i am use account( number : etc 216456)
https://drive.google.com/file/d/1xJ1X7LTd6wu_g15emuzxqHQjG5OgIkIj/view?usp=sharing

I use ngx-admin, i clone ngx-admin 5 day ago when new update Auth (link https://github.com/akveo/nebular/blob/master/docs/articles/auth-concepts-install.md) .

Thanks you for your reply.

@nnixaa nnixaa changed the title Support Login with Auth! Access token is not stored after login Nov 6, 2017
@woodm1
Copy link

woodm1 commented Nov 8, 2017

Same issue here. My token is in the header of the response from the server - do I need to change the token config from this:

token: {
key: 'data.token',
getter: (module: string, res: HttpResponse) => getDeepFromObject(res.body,
this.getConfigValue('token.key')),
}

to something else? I've tried debugging it through but can't work out what I need to change to specifically tell it where to find the token.

@woodm1
Copy link

woodm1 commented Nov 8, 2017

I'm now returning the token as json in the content of the response, i.e. 'token' : 'hsgfhgdhjfgdshfgdfgds', it
still says login succesful inititally but doesn't authenticate so auth guard won't allow a redirect.

@janabimustafa
Copy link
Contributor

You need to have your response structured as such { "data": { "token": "token_value" } }. You can also try to change the token.key from 'data.token' to just 'token' in your auth config.

-Mustafa

@aloxiao
Copy link
Author

aloxiao commented Nov 14, 2017

Dear @janabimustafa,

Where is config? Thanks!

@janabimustafa
Copy link
Contributor

janabimustafa commented Nov 14, 2017

Mine is in src\app\@core\core.module.ts (using ngx-admin).
There you can change the token key as follows:

const NB_CORE_PROVIDERS = [
  ...DataModule.forRoot().providers,
  ...NbAuthModule.forRoot({
    providers: {
      email: {
        service: NbEmailPassAuthProvider,
        config: {
          baseEndpoint: '/api',
          token: {
            key: 'token',
          },
          ...

@blankstar85
Copy link
Contributor

@janabimustafa you beat me to it. I had located this yesterday. Basically if you follow the new auth guide you just need to update the token key in the provider that you created. So this should be a file that you created in your instance and added to the module.

@woodm1
Copy link

woodm1 commented Nov 14, 2017

I ended up hacking the authenticate method in email-pass-auth provider to get it out of the body, so it doesn't need to use getConfigValue() for the token. Will have a look at refactoring it properly at some point! Thanks for the help.

@humarkx
Copy link

humarkx commented Dec 12, 2017

I also have problem with this.

Token comes from response.body.token, and cant access it

@nnixaa nnixaa added this to the rc.5 milestone Jan 22, 2018
nnixaa added a commit that referenced this issue Jan 24, 2018
@nnixaa nnixaa closed this as completed in f6887e8 Jan 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants