For us to sign someone into Google, we need to send them to the Google Login page. From there, they will sign into their account and will be redirected to our app with their Google sign-in details, from which we will extract the Google code and send it back to Google to obtain the user data that we can use in our app. This process requires the googleapis Node.js module, which is a client library for using Google APIs.
Let's get it installed and adopted in our code with the following steps:
- Install the googleapis Node.js module via npm:
$ npm i googleapis
- Create a file with your credentials so Google knows who is making the requests:
// backend/src/config/google.js
export default {
clientId: '<client ID>',
clientSecret: '<client secret>',
redirect: 'http://localhost:3000/login'
}
Note you must replace the preceding <client ID> and <client secret> values with the ID...