1- import { google } from 'googleapis '
1+ import { OAuth2Client } from 'google-auth-library '
22import crypto from 'node:crypto'
33import bcrypt from 'bcrypt'
44import type { ModuleOptions , User , GoogleOAuthOptions } from 'nuxt-users/utils'
@@ -16,7 +16,7 @@ export interface GoogleUserInfo {
1616 * Create Google OAuth2 client
1717 */
1818export function createGoogleOAuth2Client ( options : GoogleOAuthOptions , callbackUrl : string ) {
19- return new google . auth . OAuth2 (
19+ return new OAuth2Client (
2020 options . clientId ,
2121 options . clientSecret ,
2222 callbackUrl
@@ -26,7 +26,7 @@ export function createGoogleOAuth2Client(options: GoogleOAuthOptions, callbackUr
2626/**
2727 * Generate authorization URL for Google OAuth
2828 */
29- export function getGoogleAuthUrl ( oauth2Client : any , options : GoogleOAuthOptions ) : string {
29+ export function getGoogleAuthUrl ( oauth2Client : OAuth2Client , options : GoogleOAuthOptions ) : string {
3030 const scopes = options . scopes || [ 'openid' , 'profile' , 'email' ]
3131
3232 return oauth2Client . generateAuthUrl ( {
@@ -39,19 +39,29 @@ export function getGoogleAuthUrl(oauth2Client: any, options: GoogleOAuthOptions)
3939/**
4040 * Exchange authorization code for tokens and get user info
4141 */
42- export async function getGoogleUserFromCode ( oauth2Client : any , code : string ) : Promise < GoogleUserInfo > {
42+ export async function getGoogleUserFromCode ( oauth2Client : OAuth2Client , code : string ) : Promise < GoogleUserInfo > {
4343 const { tokens } = await oauth2Client . getToken ( code )
4444 oauth2Client . setCredentials ( tokens )
4545
46- const oauth2 = google . oauth2 ( { version : 'v2' , auth : oauth2Client } )
47- const { data } = await oauth2 . userinfo . get ( )
46+ // Fetch user info directly from Google's userinfo endpoint
47+ const response = await fetch ( 'https://www.googleapis.com/oauth2/v2/userinfo' , {
48+ headers : {
49+ Authorization : `Bearer ${ tokens . access_token } `
50+ }
51+ } )
52+
53+ if ( ! response . ok ) {
54+ throw new Error ( `Failed to fetch user info: ${ response . statusText } ` )
55+ }
56+
57+ const data = await response . json ( )
4858
4959 if ( ! data . email || ! data . verified_email ) {
5060 throw new Error ( 'Google account email not verified' )
5161 }
5262
5363 return {
54- id : data . id ! ,
64+ id : data . id ,
5565 email : data . email ,
5666 name : data . name || data . email . split ( '@' ) [ 0 ] ,
5767 picture : data . picture || undefined ,
0 commit comments