All files / src/utilities googleAccountGetter.js

0% Statements 0/10
0% Branches 0/6
0% Functions 0/2
0% Lines 0/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15                             
import messageResponse from "./messageResponse.js";
 
export default async function googleAccountGetter(googleUserCredentials = {}) {
    const GOOGLE_API = "https://www.googleapis.com/oauth2/v3/userinfo";
    try {
        const { token_type, access_token } = googleUserCredentials;
        const headers = { Authorization: `${token_type} ${access_token}` };
        const userinfo = await fetch(GOOGLE_API, { headers }).then(res => res.json());
        const success = userinfo?.name && userinfo?.email && userinfo?.sub
        return success ? { ok: true, googleResponse: userinfo } : messageResponse("Not found google account");
    } catch (error) {
        console.log(error)
        return { googleResponse: messageResponse(error.error) }
    }
}