fullstack-boilerplate icon indicating copy to clipboard operation
fullstack-boilerplate copied to clipboard

feat: Default authentication in Villus context

Open kingkong404 opened this issue 4 years ago • 3 comments

While the full login service is developed, I would appreciate it if we could have a basic auth setup for Villus based on default creds. Run the below function and then set context in Villus. Although I'm struggling to set the context after getting the token.

https://github.com/logaretm/villus/issues/71

    async function logInto() {
      const logData = await useMutation(LoginDocument).execute({
        email: '[email protected]',
        password: 'changeme',
      });
   // Code to set context on Villus client for future requests. 
    }

    logInto();

kingkong404 avatar Oct 22 '20 20:10 kingkong404

Looks like context in Villus has been depreciated. Any idea how you'd go about setting an Auth header with Villus after the Login Mutation?

kingkong404 avatar Oct 22 '20 21:10 kingkong404

See https://villus.logaretm.com/guide/plugins#example:-adding-authorization-headers

lewebsimple avatar Oct 23 '20 02:10 lewebsimple

The credentials (i.e. default token) should be stored in an environment variable which would serve as a feature flag for this use case. Maybe AUTH_DEFAULT_TOKEN ?

lewebsimple avatar Oct 23 '20 02:10 lewebsimple