I wonder what is the best practice to ask the user for more information to complete registration after social login with Passport. I am currently able to successfully sign in a user through Twitter, and my callback route '/auth/twitter/callback' is successfully called. However, at this point I'm presenting a form to ask them for a few more pieces of information. My problem is that at this point the req.IsAuthenticated() returns true already, while I'd rather set IsAuthenticated manually only after they complete the registration, not just as soon as the twitter callback is called. Any suggestions?
Ask user to complete registration after social login through Passport
501 Views Asked by Damiano Fusco At
1
There are 1 best solutions below
Related Questions in NODE.JS
- How to solve CERT_UNTRUSTED error in nodemailer
- Run a loop over a callback, node js
- Implementing prerender.io middleware in sails.js
- Token based authorization in nodejs/ExpressJs and Angular(Single Page Application)
- formatting path string in javascript
- One to One screensharing using WEBRTC
- Create polygon from grid (for collisions)
- Strange npm behavior when installing packages like grunt
- Convert JSON.gz to JSON in node js
- "Your npm version is outdated." but it's not. While install yo
- Why put methods on the prototype of a class instead of declaring them in the constructor?
- Node JS Async Response
- mongoose get property from nested schema after `group`
- Cannot Receive Incoming call on Twilio android Client
- How can I change a specific line in a file with node js?
Related Questions in SINGLE-SIGN-ON
- App will throw exception at when I first login when device SSO is enabled
- LDAP user attributes from CAS
- Single Sign On service hangs when configuring it
- Single Sign out in All application using Auth0
- How to logout from Bluemix Single Sign On service?
- How to add users to Cloud Directory via API?
- WSO2 IS - Do a Single Logout using the IdentitySAMLSSOService
- Skip login on MVC 3 application (SSO)
- Service broker error when adding Single Sign On service
- SAML service provider signature verification
- SAML v2 forms auth
- Combining custom application authentication with JAVA EE security. Possible?
- Bluemix Single Sign On service: Node.js code for getting the currently logged in userid?
- Apache - Configuring mod_auth_sspi.so
- Single Sign-On in Windows Applications using AD login
Related Questions in PASSPORT.JS
- Using html5 localstorage instead of cookies with passport.js
- SoundCloud Authentication Consistently Returns 401 invalid_grant For Some Users
- LDAP authentication using passport-ldapauth npm
- Loopback and passport - AccessToken 401 Permission denied
- Middleware between passport and angular
- How should i use req inside non-middleware (Passport.js)?
- Model with unique attribute is being created twice
- Send info message from verify callback to client
- Loopback passport mobile login
- Standard responses for restful API
- Password reset using password.js in sails.js
- Using react-router and express with authentication via Passport.js - possible?
- Node mongoose always returning error on findOne
- SailsJs Passport authentication for Android
- How to initiate serializeUser method when user data has changed?
Related Questions in PASSPORT-TWITTER
- Using html5 localstorage instead of cookies with passport.js
- Login with Twitter using passport.js in node.js not working
- Passport's serializeUser doesn't respond
- How to integration test a passport.js Twitter strategy implemented in express.js?
- Node.js Loopback Framework + Twitter oauth doesn't work on a live server
- Passport.authenticate() gets stucks
- Call Passport API endpoint protected by passport-twitter strategy from Postman
- Twitter authentication with Passport middleware in Node
- Delete cookie from user browser after the session ends. Im using Passport-twitter to authenticate the user.
- Linking Twitter account to user account (twitter-passport)
- Node.js passport-twitter: Unable to get user email in passport-twitter authentication
- Express, Create-React-App, & passport-twitter
- InternalOAuthError: failed to obtain request token passport-twitter
- passport-twitter returns "Failed to load resource: the server responded with a status of 500 (Internal Server Error)"
- Ask user to complete registration after social login through Passport
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
There are a few ways you can achieve what you want to do and from my point of view fiddling around with
req.isAuthenticated()is not the best. I recommend the following approaches.Method 1
In addition to
req.isAuthenticated()put a new condition to check whether the user completed registration or not i.e.user.completedRegistration()wherecompletedRegistration()is a function that checks either mongodb or some other logic to decide yes or not. Sample as follow:You obviously will use the isAuthenticated in your routes, as follow:
user.completedRegistration()could be a function that queries, the mongodb for the logged in user using the logged in user id (twitter id) and check if a particular field is set. You set this field when the user register otherwise by default it can be false.Method 2
Depending on ordering of your configs in the app.js every request runs the deserializeUser as shown below:
Which takes the id of the logged in user from req object and retrieves the user from mongodb and populate more information about user in the req object. You can tweak this method to
User.findusing not only id of the user but, a field that shows whether the user is registered or not. Obviously you need to set the field in the mongodb user object and theUsermodel.Method 3
Leave alone the passport related configs, write your own checks in the router level to check whether the logged in user is registered or not. You can do this using the following steps:
To obtain the id of the logged in user, you can check the
req.userfield. As shown in the following function, I have implementedtwitter,facebookandlocaland hence all my checks.There are many other ways to achieve what you have asked for in here but, you need to do some reading on the express app combined with passport work and then you will get an understanding of where to intercept the user requests and which approach suits you best.