nuxt-graphql-request
nuxt-graphql-request copied to clipboard
Auth Integration
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.
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.
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 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.
@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 plugin can’t listen dynamic changes of auth state. It works only aftet page refresh