Auth Fails after email validation


#1

I have a two problems with my code. First User cannot login after the user clicks on the validation link sent to their email address.
Second flash messages fails.

But when I copy and paste the validation link that is sent to the user email on the browser and hit enter, every thing works perfectly.

Here is my code

async confirmEmail({params,session,response, auth}) {

    try {
        //get user with confirmation token
        const user = await User.findBy('u_confirmation_token', params.token)

        //set confirmation null and is active to true
        user.u_is_active = true

        //persist user to database
        await user.save()

        //display success message
        session.flash({
            alert: {
                type: 'success',
                title: 'Success!',
                message: 'You successfully confirmed your email address!',
                ButtonText: 'Cool'
            }
        })
        try {
            await auth.remember(!!false).loginViaId(user.id)
            return response.redirect('/')
        } catch (error) {
            return response.redirect('/login')
        }

    } catch (error) {

        session.flash({
            alert: {
                type: 'error',
                title: 'Erro!',
                message: 'Email Confirmation failed',
                ButtonText: 'Resend Token'
            }
        })
    }

    return response.redirect('/')

}

#2

Answered Session flash message fails occasionally