Help in Adonis social Authentication


#1

Hello Im following the authentication tutorial of the oficial documentation, but I have the following error, any idea? thanks

E_UNDEFINED_METHOD: Method redirect missing on App/Controllers/Http/LoginController > More details: https://err.sh/adonisjs/errors/E_UNDEFINED_METHOD 

Yes I have the method declared inside the controller, the keys of facebook declared


#2

I didn’t use a controller, but this works successfully for me.

Route.get('facebook', async ({ ally }) => {
  await ally.driver('facebook').redirect()
})

Route.get('/auth/facebook', async ({ ally, response }) => {
  let user = await ally.driver('facebook').getUser()

  response.ok(user)
})

EDIT:

Here it is in a controller. (works well here too)

class LoginController {
  async redirect ({ ally }) {
    await ally.driver('facebook').redirect()
  }

  async callback ({ ally, response }) {
    let user = await ally.driver('facebook').getUser()

    response.ok(user)
  }
}

What does your routes file look like?


#3

these are my routes

Route.get(‘login/facebook’, ‘LoginController.redirect’)
Route.get(‘facebook/callback’, ‘LoginController.callback’)


#4

And there is no typo in your controller action name, correct?


#5

No man, in fact Im following the tutoriasl provided by the official documentation but im not sure what’s the problem :smiley:


#6

Do you mind sharing the project? I can try to spin it up on my machine.


#7

yeah thanks give a minutes


#8

With your help I already have not the same error, but now i hvae this one

{
“error”: {
“message”: “redirect_uri isn’t an absolute URI. Check RFC 3986.”,
“type”: “OAuthException”,
“code”: 191,
“fbtrace_id”: “CDgzLNLJ8Uy”
}
}


#9

Hmm are you using localhost as the facebook url?


#10

yeah im using it


#11

Ok that’s the problem. Think about it at facebook they also have servers so calling localhost will resolve to their internal machines.

To get around this use something like ngrok.

Install via npm npm install ngrok -g or
If you have homebrew use brew cask install ngrok

Then run ngrok http 3333 from your adonis project. This will create a tunnel directly to your machine


#12

oh my God i didn’t know let my try your idea many thanks for your time