You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello guys, noob here, I'm trying to figure out how to do this right. I'm getting authenticated by Facebook without a problem, but when I got to the part of using the actual data from Facebook I got stuck... I've been copying from here and there. How would you go about using the info received from the OAuth thing?
Here's my code, I've been referencing GitHunt and Jonas' auth article mainly.
importexpressfrom'express';importpathfrom'path';importuuidfrom'node-uuid';// GraphQLimport{apolloServer}from'apollo-server';importschemafrom'./postgres/schema';importresolversfrom'./postgres/resolvers';// Webpackimportwebpackfrom'webpack';importwebpackMiddlewarefrom'webpack-dev-middleware';importwebpackHotMiddlewarefrom'webpack-hot-middleware';importconfigfrom'../webpack.config.dev.js';// AuthenticationimportbodyParserfrom'body-parser';importcookieParserfrom'cookie-parser';importsessionfrom'express-session';importpassportfrom'passport';import{StrategyasFacebookStrategy}from'passport-facebook';importfacebookStrategyOptionsfrom'./auth/config';// Knex Sessionimportknexfrom'./postgres/connectors';constKnexSessionStore=require('connect-session-knex')(session);conststore=newKnexSessionStore({ knex });import{User}from'./postgres/models/User';constuserModel=newUser();// Routesimportroutesfrom'./routes';importfacebookfrom'./routes/auth/facebook';importlocalfrom'./routes/auth/local';constGRAPHQL_PORT=3000;constapp=express();constcompiler=webpack(config);app.use(webpackMiddleware(compiler,{hot: true,noInfo: true,publicPath: config.output.publicPath,stats: {colors: true,timings: true,modules: false}}));app.use(webpackHotMiddleware(compiler));// React front endapp.get('/',(req,res)=>{res.sendFile(path.join(__dirname,'../client/index.html'));});app.get('/logout',(req,res)=>{req.logout();res.redirect('/');});app.use('/graphql',apolloServer({graphiql: true,pretty: true,
schema,
resolvers
}));// Authenticationapp.use(session({saveUninitialized: true,resave: true,genid: req=>{returnuuid.v4();},secret: 'Z3]GJW!?9uP”/Kpe',
store
}));app.use(passport.initialize());app.use(passport.session());app.get('/login/facebook',passport.authenticate('facebook',{scope: ['email']}));app.get('/login/facebook/callback',passport.authenticate('facebook',{failureRedirect: '/bleh',successRedirect: '/'}),(req,res)=>res.redirect('/'));// Parsingapp.use(bodyParser.json());app.use(bodyParser.urlencoded({extended: false}));passport.use(newFacebookStrategy(facebookStrategyOptions,(accessToken,refreshToken,profile,cb)=>{console.log(profile);// The info I need is there, but I can't figure out how to use ituserModel.findFacebook(profile).then(user=>{if(user){returndone(null,user)}else{userModel.createFacebook(profile).then(newUser=>{returndone(null,newUser)})}}).catch(error=>console.log('Oh no...',error));cb(null,profile);}));passport.serializeUser((user,cb)=>cb(null,user));passport.deserializeUser((obj,cb)=>cb(null,obj));app.listen(GRAPHQL_PORT,()=>console.log(`GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}/graphql`));
The text was updated successfully, but these errors were encountered:
Can you be a bit more specific on where you're stuck? Also, you might have more luck asking on the Apollo slack channel, because technically this isn't an apollo-server issue.
Hello guys, noob here, I'm trying to figure out how to do this right. I'm getting authenticated by Facebook without a problem, but when I got to the part of using the actual data from Facebook I got stuck... I've been copying from here and there. How would you go about using the info received from the OAuth thing?
Here's my code, I've been referencing GitHunt and Jonas' auth article mainly.
The text was updated successfully, but these errors were encountered: