Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const adminToken = adminUserAuthToken
if (userToken) {
return identity
.getUserWithToken(userToken)
.then(data => ({ userId: data.userId, email: data.user }))
} else if (!userToken && !!adminToken) {
const adminInfo = jwtDecode(adminToken) as any
const callOpUserEmail = adminInfo && adminInfo.sub
const isValidCallOp =
callOpUserEmail &&
(await isValidCallcenterOperator(context, callOpUserEmail))
if (!isValidCallOp) {
throw new AuthenticationError('User is not a valid callcenter operator')
}
const customerEmail = parsedCookies['vtex-impersonated-customer-email']
return profile
.getProfileInfo({ email: customerEmail, userId: '' })
.then(({ email, userId }) => ({ email, userId }))
}
return null
}
export function statusToError(e: any) {
if (!e.response) {
throw e
}
const { response } = e as AxiosError
const { status } = response!
if (status === 401) {
throw new AuthenticationError(e)
}
if (status === 403) {
throw new ForbiddenError(e)
}
if (status === 400) {
throw new UserInputError(e)
}
throw e
}
export function statusToError(e: any) {
if (!e.response) {
throw e
}
const { response } = e as AxiosError
const { status } = response!
if (status === 401) {
throw new AuthenticationError(e)
}
if (status === 403) {
throw new ForbiddenError(e)
}
if (status === 400) {
throw new UserInputError(e)
}
throw e
}