0

I have a AdonisJS view module that use an external API to authenticate. But Don't know how can set this user in my auth object.

    async login({ request, response, session, auth }){
        const {email, password} = request.only(['email', 'password'])

        try{
           //resp contains user data retrieved
            const resp = await axios.post('myHost/login', {
                "email": email,
                "password": password
            });

            return response.redirect(request.header('origin'))
        }catch(error) {
            session.flash({ 'error': 'Test error' })
        };    
    }

I tried set this object in response header, but, isn't correct.

Popmedic
  • 1,791
  • 1
  • 16
  • 21
  • Regarding JWT you have two options. (1) save the JWT in the browser local storage and add the JWT on each `axios` request that needs authentication. (2) JWT-Cookie which is a bit similar to the first solution but the server is the one that sets the JWT at the client side. – Daniel Jul 21 '20 at 13:18
  • I can use de cookie approach. But, using Adonisjs auth, i need identify an user with @loggedIn tag in my web page. I guess that this tag need auth.user object. – Fabio Lopes Jul 21 '20 at 18:12
  • According to the docs the user info is a member of auth (see https://adonisjs.com/docs/4.0/authentication#_showing_profile). Sadly I don't know about how the `@loggedIn` works here. – Daniel Jul 22 '20 at 10:42

0 Answers0