How can set in session a user authenticated under a external API using AdonisJs?

420 Views Asked by At

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.

0

There are 0 best solutions below