StephenGrider / FullstackReactCode

Companion repo to https://www.udemy.com/node-with-react-fullstack-web-development
1.39k stars 1.17k forks source link

TokenError: Code was already redeemed #25

Open ConnorIngold opened 6 years ago

ConnorIngold commented 6 years ago

Hi,

Anyone else had this problem? asked on Udemy as well. I spent ages trying to find a solution.

Heres my index.js:

const express = require('express');
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const keys = require('./config/keys');

const app = express();

passport.use(
    new GoogleStrategy(
        {
            clientID: keys.googleClientID,
            clientSecret: keys.googleClientSecret,
            callbackURL: '/auth/google/callback'
        },
        accessToken => {
            console.log('accessToken');
        }
    )
);

app.get(
    '/auth/google',
    passport.authenticate('google', {
        scope: ['profile', 'email']  
    })
);

app.get('/auth/google/callback', passport.authenticate('google'));

const PORT = process.env.PORT || 5000;
app.listen(PORT);

Heres my terminal:

accessToken
TokenError: Code was already redeemed.
    at Strategy.OAuth2Strategy.parseErrorResponse (/Users/connoringold/code/killercarwash/full-stack-javascript-website/node_modules/passport-oauth2/lib/strategy.js:329:12)
    at Strategy.OAuth2Strategy._createOAuthError (/Users/connoringold/code/killercarwash/full-stack-javascript-website/node_modules/passport-oauth2/lib/strategy.js:376:16)
    at /Users/connoringold/code/killercarwash/full-stack-javascript-website/node_modules/passport-oauth2/lib/strategy.js:166:45
    at /Users/connoringold/code/killercarwash/full-stack-javascript-website/node_modules/oauth/lib/oauth2.js:191:18
    at passBackControl (/Users/connoringold/code/killercarwash/full-stack-javascript-website/node_modules/oauth/lib/oauth2.js:132:9)
    at IncomingMessage.<anonymous> (/Users/connoringold/code/killercarwash/full-stack-javascript-website/node_modules/oauth/lib/oauth2.js:157:7)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
fijiwebdesign commented 6 years ago

There's a discussion here on solutions: https://github.com/jaredhanson/passport-google-oauth/issues/82