check for android source in api mobile sign up route

This commit is contained in:
Satindar Dhillon
2022-08-19 18:53:51 -07:00
parent fd69fd8aa7
commit 33a4ee39dc
3 changed files with 17 additions and 9 deletions

View File

@ -57,22 +57,23 @@ export const validateGoogleUser = async (
}
}
const iosClientId = env.google.auth.iosClientId
const androidClientId = env.google.auth.androidClientId
const googleWebClient = new OAuth2Client(env.google.auth.clientId)
const googleIOSClient = new OAuth2Client(iosClientId)
const googleAndroidClient = new OAuth2Client(androidClientId)
export async function decodeGoogleToken(
idToken: string,
isAndroid: boolean
): Promise<DecodeTokenResult> {
try {
const clientID = isAndroid
? env.google.auth.androidClientId
: env.google.auth.iosClientId
const googleMobileClient = new OAuth2Client(clientID)
const googleMobileClient = isAndroid ? googleAndroidClient : googleIOSClient
const loginTicket = await googleMobileClient.verifyIdToken({
idToken,
audience: clientID,
audience: isAndroid ? androidClientId : iosClientId,
})
const email = loginTicket.getPayload()?.email

View File

@ -40,8 +40,14 @@ export function mobileAuthRouter() {
})
router.post('/sign-up', async (req, res) => {
const { token, provider, name } = req.body
const payload = await createMobileSignUpResponse(token, provider, name)
const { token, provider, name, source } = req.body
const isAndroid = source === 'ANDROID'
const payload = await createMobileSignUpResponse(
isAndroid,
token,
provider,
name
)
res.status(payload.statusCode).json(payload.json)
})

View File

@ -13,13 +13,14 @@ import { hashPassword } from '../../../utils/auth'
import { createUser } from '../../../services/create_user'
export async function createMobileSignUpResponse(
isAndroid: boolean,
token?: string,
provider?: AuthProvider,
name?: string
): Promise<JsonResponsePayload> {
try {
if (token && provider === 'GOOGLE') {
const decodedTokenResult = await decodeGoogleToken(token)
const decodedTokenResult = await decodeGoogleToken(token, isAndroid)
return createSignUpResponsePayload(
provider,
decodedTokenResult,