{ [FacebookTokenError: This authorization code has been used.]

烂漫一生 提交于 2019-12-05 19:12:13

This error occurs when you logged using facebook login, after that delete the user record in your database. You must delete your APP in your facebook account and try again.

Another posibility is that you already are logged in, and your middleware is trying to login again. In your code, you are not checking if the user is already logged in before send the request to "auth/facebook. There is a simple way to prove this: Open a Chrome window in private mode, so no cookie is used, and try again your facebook login. Good Luck!

Probabily not exist some attributes of profile data. Try:

console.log(profile)

For verify all attributes of profile. In my case:

{ id: 'nnnnnnnn',
  username: undefined,
  displayName: 'My Name',
  name: 
   { familyName: undefined,
     givenName: undefined,
     middleName: undefined },
  gender: undefined,
  profileUrl: undefined,
  provider: 'facebook',
  _raw: '{"name":"My name","id":"nnnnnnnn"}',
  _json: { name: 'My name', id: 'nnnnnnnn' } }

Not exist any attribute "email" or similar, this generate the error and not complete the cicle life of the authenticate:

error: FacebookTokenError: This authorization code has been used.

The attribute email not get because I hidden this in my account Facebook.

In your code:

...
var data = {
   provider: profile.provider,
   uid: profile.id,
   name: profile.displayName,
   email: profile.email
};
...

The line:

email: profile.email

You are already assuming that the attribute email is already exist.

Try:

email: (profile.emails && profile.emails[0]) ? profile.emails[0].value : ''
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!