Code Monkey home page Code Monkey logo

Comments (3)

danielbankhead avatar danielbankhead commented on June 5, 2024 1

Suppose I log in to Google and get redirected to a callback URL where I update my user information in the database using Node. How will my front end know whether the login was successful?

That would depend on your authorization model - if redirecting the successful response from the backend confirms a successful login.

To make this easier I would recommend the Google Identity Services JavaScript library for the frontend:

Further reading:

from google-auth-library-nodejs.

danielbankhead avatar danielbankhead commented on June 5, 2024

How to use nodejs api of google auth in axios fetch using API URL directly on anchor tag is not safe and fetching this using axios is not working as expected

I do not understand this question, perhaps these resources can be of assistance:

from google-auth-library-nodejs.

startthecode avatar startthecode commented on June 5, 2024

Hi @danielbankhead,
Suppose I log in to Google and get redirected to a callback URL where I update my user information in the database using Node. How will my front end know whether the login was successful? Should I call an API to check whether the user was created successfully?

My approach

  1. Upon receiving data on the callback route, the server will first update the database. Then, it will set an encrypted data cookie on the frontend using "res.cookie" and redirect to the frontend URL using "res.redirect(frontend)".
  2. The frontend will check if the URL contains something like "google auth success". If it does, the frontend will fetch an API that contains the cookie saved by the server to retrieve the data of the Google logged-in user.
  3. The server will verify the encrypted data that comes with the API request. If the encrypted data is verified, the server will return an auth token (with a maximum age of 15 days, which can also help to refresh the access token) and an access token (with a maximum age of 1 hour).

Many thanks
Ashish

from google-auth-library-nodejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.