Skip to content

Instantly share code, notes, and snippets.

@shangyilim
Created April 1, 2019 10:59
Show Gist options
  • Save shangyilim/07fc40d5e96921d73d4d956b4863468a to your computer and use it in GitHub Desktop.
Save shangyilim/07fc40d5e96921d73d4d956b4863468a to your computer and use it in GitHub Desktop.
import { google } from 'googleapis';
app.post('/sendSMS', function (req, res) {
const { phoneNumber, recaptchaToken } = req.body;
const identityToolkit = google.identitytoolkit({
auth: 'GCP_API_KEY',
version: 'v3',
});
await identityToolkit.relyingparty.verifyPhoneNumber({
code: verificationCode,
sessionInfo: phoneSessionId,
});
// verification code accepted, update phoneNumberVerified flag in database
// ...
});
@skibaalex
Copy link

skibaalex commented Sep 5, 2020

i believe there is a small issue with that code phoneSessionId is unidentified

import { google } from 'googleapis';

app.post('/sendSMS', function (req, res) {
  const { phoneNumber, recaptchaToken } = req.body;
  
  const identityToolkit = google.identitytoolkit({
    auth: 'GCP_API_KEY',
    version: 'v3',
  });
  
  const response = await identityToolkit.relyingparty.sendVerificationCode({
    phoneNumber,
    recaptchaToken: recaptcha,
  });
  
 // save sessionInfo into db. You will need this to verify the SMS code
 const sessionInfo = response.data.sessionInfo;
 
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment