DEV Community

Building an API with AdonisJS (part 2)

Danilo Miranda on March 05, 2019

This is the second post of the series about creating an API using AdonisJS. If you didn't read the first part here is the link Building an API with...
Collapse
 
mavguimaraes profile image
mavguimaraes

I am studying your tutorial on Building an API with Adonisjs (2nd part) and when I click on the link to recover the password I get the following:
HttpException
E_ROUTE_NOT_FOUND: Route not found GET /users/forgotPassword/ba101e9c3d63dd821ab2/maguimar@fe.up.pt
I do not know what could be wrong since the code is the same as the tutorial

Collapse
 
nilomiranda profile image
Danilo Miranda

Hey Mav, really happy to see that you are using my guide, I hope it's of good use for you.

Are you clicking in the link generated inside the email? Or are you just copying the token up to the email part of the link?

If you wish, send me a DM on twitter and I'll help you out 🙂🙂

Collapse
 
njoanc profile image
NYIRAMWIZA

I have the same issue. I am clicking on the link found inside the email. Even when I try with postman, I get the same error

Thread Thread
 
10yine profile image
michael elias

hello

Collapse
 
njoanc profile image
NYIRAMWIZA

I have the same issue

Collapse
 
fozz2k profile image
Mark Forrest

Use PUT not GET in your REST client

Collapse
 
christopaixao profile image
Christopher Paixão

ótima série de posts!
vc poderia me ajudar com um problema que estou tendo?
estou com uma api no adonisjs sendo consumida pelo ionic,
gostaria que ao fazer login o usuario fosse direcionado para uma pagina de perfil, esta página é acessada por localhost:8100/profile/IDUSUARIO.
Colocando o ID manualmente eu consigo visualizar o perfil do usuário porém ao fazer login eu quero retorna o id no resultado.

método login no adonisjs:

async login({ request, auth, response }) {
    const email = request.input("email")
    const password = request.input("password");
    try {
        if (await auth.attempt(email, password, id)) {
            let user = await User.findBy('email', email)
            let accessToken = await auth.generate(user)
            return response.json({ "user": user, "access_token": accessToken})

        }

    }
    catch (e) {
        return response.json({ message: 'You first need to register!' })
    }
}
Collapse
 
iampick profile image
iampick

Hi,

Thank you for your guide. I have a problem when tried to use JWT Auth with insomnia. Where can I check this?

Thank you.

Collapse
 
nilomiranda profile image
Danilo Miranda

Hi,

How are you sending the token via insomnia?

Collapse
 
njoanc profile image
NYIRAMWIZA

Hey! Here how I am sending the token via postman

127.0.0.1:3333/reset/7687930908790...

Collapse
 
arapl3y profile image
Alex Rapley

Thanks for the tutorials! This line was causing me issues: user.token_created_at = 0

However changing it to: user.token_created_at = null fixed the issue

Collapse
 
aleishizawa profile image
Alessandro Navarro Ishizawa

Olá Danilo, muito bom e útil essa série de posts !!!
Estou seguindo os steps, o e-mail está sendo enviado, tokens gerados, só tenho uma dúvida, estou fazendo esse modelo de redefinição de senha para um app em react-native, quando clico no link do e-mail(e abre pelo navegador), da o erro de rota HttpException
E_ROUTE_NOT_FOUND: Route not found GET /users/forgotPassword, pois como no tutorial ela foi definida como PUT, deveria criar outra rota GET para pegar esses parâmetros via URL, ou alterar a mesma para GET ? o que sugere ?

Collapse
 
anthony4m profile image
Anthony Amoah

how do i signin

Collapse
 
raphaeljansson profile image
RaphaelJansson

I had a problem with Mail then I used Nodemailer, it worked very well.

Collapse
 
anthony4m profile image
Anthony Amoah

am following the series and i'm running to a problem i am trying to login using the login function but i keep getting 401 error i dont know what i am doing wrong

Collapse
 
necati12 profile image
necati12

Hi,
I like your work and I can say you. a great job..