check for android source in api mobile sign up route
This commit is contained in:
@ -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
|
||||
|
||||
@ -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)
|
||||
})
|
||||
|
||||
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user