diff --git a/src/routes/oauth2-signin.ts b/src/routes/oauth2-signin.ts index b005b85..45352db 100644 --- a/src/routes/oauth2-signin.ts +++ b/src/routes/oauth2-signin.ts @@ -4,6 +4,7 @@ import { AceBaseUserSignInEmailRequest, AceBaseUserSignupEmailRequest } from '.. import { RouteInitEnvironment, RouteRequest } from '../shared/env'; import { createPasswordHash, generatePassword } from '../shared/password'; import { createPublicAccessToken, createSignedPublicToken, parseSignedPublicToken } from '../shared/tokens'; +import { fetch } from '../shared/simple-fetch'; const socketSignInSuccess = `
Signed in succesfully. You can close this page`; const socketSignInFailed = `Failed to sign in. You can close this page`; @@ -51,10 +52,8 @@ export const addRoute = (env: RouteInitEnvironment) => { if (user_details.picture && user_details.picture.length > 0) { // Download it, convert to base64 const best = user_details.picture.sort((a,b) => a.width * a.height > b.width * b.height ? -1 : 1)[0] - // TODO: Let client do this instead: - const { fetch } = require('./oauth-providers/simple-fetch'); - await fetch(best.url) - .then(async response => { + try { + const response = await fetch(best.url); const contentType = response.headers.get('Content-Type'); if (contentType === 'image/png') { //state.provider === 'google' && // Don't accept image/png, because it's probably a placeholder image. Google does this by creating a png with people's initials @@ -65,11 +64,11 @@ export const addRoute = (env: RouteInitEnvironment) => { let buff = Buffer.from(image); best.url = `data:${contentType};base64,${buff.toString('base64')}`; user_details.picture = [best]; // Only keep the best one - }) - .catch(err => { + } + catch(err) { env.debug.warn(`Could not fetch profile picture from "${best.url}": `, err); user_details.picture = null; - }); + } } const getProviderSettings = () => {