nuxt-graphql-request icon indicating copy to clipboard operation
nuxt-graphql-request copied to clipboard

Auth Integration

Open yondifon opened this issue 4 years ago • 5 comments
trafficstars

I think there most be a better way to integrate this plugin with nuxt-auth. Setting the bearer anytime you to want to send a request isn't not realistic.

yondifon avatar Jan 17 '21 11:01 yondifon

You only have to do it the first time the person logs in. It isn’t saved on a hard reload because this is a lightweight plugin by design.

But if you want that, it’s easy enough to just save the token to a cookie on successful login and check for that on page load.

drewbaker avatar Jan 17 '21 17:01 drewbaker

Here's a lil work around it. Create a plugin

// plugin/auth-graphql.ts 
export default function ({ $graphql, app }: any) {
    if (app.$auth)
        $graphql.setHeader('authorization', app.$auth.strategy.token.get());
}

Then include this in config file

{
  ...
  auth: {
    plugins: ['~/plugins/auth-graphql.ts'],
    ...
  }
}

yondifon avatar Jan 20 '21 03:01 yondifon

@yondifon it's not working when token is changing - for example after login, header doesn't added for the next requests - you need to refresh the page.

Chernavskikh avatar Mar 09 '21 11:03 Chernavskikh

@yondifon it's not working when token is changing - for example after login, header doesn't added for the next requests - you need to refresh the page.

@Chernavskikh How do you mean?

yondifon avatar Mar 09 '21 14:03 yondifon

@yondifon plugin can’t listen dynamic changes of auth state. It works only aftet page refresh

Chernavskikh avatar Mar 30 '21 18:03 Chernavskikh