passport.js

passport.js session lost after redirect

这一生的挚爱 提交于 2021-02-19 05:42:08
问题 I am trying to integrate passport into my node.js app. app.js file const app = express(); app.set('view engine', 'pug'); app.use('/libs', express.static('node_modules')); require('../config/auth.config')(app, data, passport); app.use((req, res, next) => { res.locals.user = req.user; next(); }); app.get('/', (req, res) => { // those objects are populated correctly after redirect from auth middleware console.log(req.session) console.log(req.user) return res.render('home'); }); app.get('/login',

Why is passport.deserializeUser called after req.user has been restored?

橙三吉。 提交于 2021-02-11 16:38:44
问题 According to the Passport Documentation on Sessions ...only the user ID is serialized to the session, keeping the amount of data stored within the session small. When subsequent requests are received, this ID is used to find the user, which will be restored to req.user. However my test SPA which is based on Passport form-based authentication sample with debug messages added indicates req.user has already been restored before the app.get route handler is triggered. Here is the output from an

Why is passport.deserializeUser called after req.user has been restored?

痞子三分冷 提交于 2021-02-11 16:37:13
问题 According to the Passport Documentation on Sessions ...only the user ID is serialized to the session, keeping the amount of data stored within the session small. When subsequent requests are received, this ID is used to find the user, which will be restored to req.user. However my test SPA which is based on Passport form-based authentication sample with debug messages added indicates req.user has already been restored before the app.get route handler is triggered. Here is the output from an

Why is passport.deserializeUser called after req.user has been restored?

两盒软妹~` 提交于 2021-02-11 16:37:06
问题 According to the Passport Documentation on Sessions ...only the user ID is serialized to the session, keeping the amount of data stored within the session small. When subsequent requests are received, this ID is used to find the user, which will be restored to req.user. However my test SPA which is based on Passport form-based authentication sample with debug messages added indicates req.user has already been restored before the app.get route handler is triggered. Here is the output from an

What's the best way to authenticate and authorize a web and api solution like MERN Stack?

半城伤御伤魂 提交于 2021-02-11 15:19:16
问题 I'm trying to find the best way to implement authorization. At this time, only thing I need is a simple free account, but later I may include user roles for a "premium" account using a payment system like stripe. I have already started reading and experimenting with Auth0 but then found some other ways I can do it. Passport.js + MongoDB, I've seen some examples and work great but I think it is missing a way to control users, rules etc with a friendly panel (like Auth0) Using Auth0 and setting

Mongoose - Unable to create more than 4 fields using `findOrCreate`

落爺英雄遲暮 提交于 2021-02-11 14:01:02
问题 I am using Node.js, MongoDB with Mongoose and am using passport.js for authentication. Here is my user schema: const userSchema = new mongoose.Schema({ email: String, password: String, googleId: String, facebookId: String, profilePic: String, fName: String, lName: String }); And my google strategy: passport.use( new GoogleStrategy( { clientID: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_SECRET, callbackURL: "http://localhost:3000/auth/google/dashboard", profileFields: ["id",

passport.authenticate - username and password are null

此生再无相见时 提交于 2021-02-10 11:54:09
问题 this is probably some basic mistake but I am watching tutorial and even though I think I done everything exactly like I should after submitting login form I am redirected to the "failureRedirect" page. When I looked at source code in passport module I something. After this: Strategy.prototype.authenticate = function(req, options) { options = options || {}; var username = lookup(req.body, this._usernameField) || lookup(req.query, this._usernameField); var password = lookup(req.body, this.

How to use passport-google-oauth20 with a SPA react application?

允我心安 提交于 2021-02-10 04:50:50
问题 How do I trigger the Google Sign In authorization window to popup? I'm using JaredHanons' "passport-google-oauth20" library to help with authentication on an application in combination with JSON WebTokens. My frontend is a single page application with react. I currently have a node.js/express.js api backend and, right now, a separate frontend dev server with react. Frontend wise I have a login button calling: axios.get("http://localhost:3000/oauth/google/getToken/") Which is hitting: `app.get

How to use passport-google-oauth20 with a SPA react application?

泄露秘密 提交于 2021-02-10 04:48:28
问题 How do I trigger the Google Sign In authorization window to popup? I'm using JaredHanons' "passport-google-oauth20" library to help with authentication on an application in combination with JSON WebTokens. My frontend is a single page application with react. I currently have a node.js/express.js api backend and, right now, a separate frontend dev server with react. Frontend wise I have a login button calling: axios.get("http://localhost:3000/oauth/google/getToken/") Which is hitting: `app.get