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
- Using Puppeteer to scrape a public API only when the data changes
- How to request administrator rights?
- How do I link two models in mongoose?
- Variable inside a Variable, not updating
- Unable to Post Form Data to MongoDB because of picturepath
- Connection terminated unexpectedly while performing multi row insert using pg-promise
- Processing multiple forms in nodejs and postgresql
- Node.js Server + Socket.IO + Android Mobile Applicatoin XHR Polling Error...?
- How to change the Font Weight of a SelectValue component in React when a SelectItem is selected?
- My unban and ban commands arent showing when i put the slash
- how to make read only file/directory in Mac writable
- How can I outsource worker processes within a for loop?
- Get remote MKV file metadata using nodejs
- Adding google-profanity-words to web page
- Products aren't displayed after fetching data from mysql db (node.js & express)
Related Questions in SINGLE-SIGN-ON
- Generate Databricks personal access token using REST API
- Allow external users to login using custom SAML app in Google Admin
- Handling errors in MSAL Redirect - reactjs login with microsoft sso
- How would single sign-on work for my multi-tenant application?
- How can we make an environment specific Token-based authorization using Ping Token?
- Is it possible to integrate Looker Studio with websites without keeping it public, to preserve data?
- OKTA SSO Driven API Invocation
- Is there any way to login SSO using RestAssured or using any API calls?
- Is it possible to interact with SSO between Website A and Website B?
- SSO to Grafana embeded in iframe
- Secure React App and .net 6 apis with Keycloack
- Integrating one tap sign in with phone from phone email - Converting html and javascript code to React JS
- I need SSO and Maven to work together in a Tomcat 9 Eclipse project, I have check the usual suspects but I think I missed something
- Firebase Authentication SAML resource metadata file
- How to add ForceAuthn flag on AWS cognito
Related Questions in PASSPORT.JS
- The "local" function in passport.authenticate is not being invoked for some reason
- Unable to save session with passport.js after signing up
- Implementing a login system using react and passport local
- Trouble Sending JWT from Backend to Frontend after Google OAuth Login
- How to solve user.get is not a function error?
- Must the fetch method request correspond to the server side http method
- nestjs Login sessions require session support
- passport-spotify accessToken undefined in session
- Express doesn't redirect to react-router root path after successful MongoDB save - fails silently - how to redirect successfully?
- local Passport and express backend works when using postman but not when using react and react-query frontend
- Error 401 on Angular-NestJs page when refreshing token with Auth0
- NestJS Local Auth Guard always returning 401 Unauthorized
- Google authentication is redirecting to http version of my site
- Nest can't resolve dependencies of the UserService (?). Please make sure that the argument "UserRepository" at index [0]
- After redirection from the server, a 'Cross-Origin Request Blocked' error is encountered in Next 14
Related Questions in PASSPORT-TWITTER
- Communication with twitter in oauth1 user context on my backend express
- double passport connexion twitter and discord
- Node.js passport-twitter: Unable to get user email in passport-twitter authentication
- Linking Twitter account to user account (twitter-passport)
- InternalOAuthError: failed to obtain request token passport-twitter
- http://localhost:3000 or http://127.0.0.1:3000 both are invalid website URL in Twitter Developer App for User Authentication
- error when setting twitter oauthv1 with passportjs
- How do i get the twitter return url when authenticating using passport twitter
- Twitter OAuth Strategy Access Level & Email Problem
- Authenticating by twitter in Nodejs stateless
- Call Passport API endpoint protected by passport-twitter strategy from Postman
- Passport.authenticate() gets stucks
- Tweet on user profile using Twit package
- Social Login in NestJS using @AuthGuard, Passport
- Passport-twitter strategy requires refresh to provide token
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 # Hahtags
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.