diff --git a/env.d.ts b/env.d.ts index 4d291ae..1b51202 100644 --- a/env.d.ts +++ b/env.d.ts @@ -19,6 +19,13 @@ interface GoogleAccounts { logo_alignment?: 'left' | 'center' }) => void } + oauth2: { + initTokenClient: (config: { + client_id: string + callback: (response: { access_token: string }) => void + scope?: string + }) => void + } } } diff --git a/src/views/login/SignupPage.vue b/src/views/login/SignupPage.vue index ab0b56e..9f7fcf9 100644 --- a/src/views/login/SignupPage.vue +++ b/src/views/login/SignupPage.vue @@ -30,7 +30,7 @@ - + @@ -130,7 +130,10 @@ const handleConfirm = async () => { isLoading.value = false }) } - +const googleSignupRef = ref(null) +const clickGooleLogin = () => { + googleSignupRef.value?.login() +} // 处理Google注册 const handleGoogleSignup = async (credential: string) => { try { diff --git a/src/views/login/components/GoogleLogin.vue b/src/views/login/components/GoogleLogin.vue index 01fc123..e85ce0a 100644 --- a/src/views/login/components/GoogleLogin.vue +++ b/src/views/login/components/GoogleLogin.vue @@ -25,23 +25,23 @@ const emit = defineEmits<{ }>() // 处理 Google 登录回调 -const handleCredentialResponse = async (response: { access_token: string }) => { +const handleCredentialResponse = async (response: { access_token: string, credential: string }) => { console.log('Google 登录响应:', response) - fetch('https://www.googleapis.com/oauth2/v3/userinfo', { - headers: { - 'Authorization': `Bearer ${response.access_token}` - } - }) - .then(response => response.json()) - .then(userInfo => { - console.log('User info:', userInfo); - }) - .catch(error => { - console.error('Error fetching user info:', error); - }); -// const code = response.credential -// emit('googelLogin', code) -// window.isAddGmail = false +// fetch('https://www.googleapis.com/oauth2/v3/userinfo', { +// headers: { +// 'Authorization': `Bearer ${response.access_token}` +// } +// }) +// .then(response => response.json()) +// .then(userInfo => { +// console.log('User info:', userInfo); +// }) +// .catch(error => { +// console.error('Error fetching user info:', error); +// }); + const code = response.access_token + emit('googelLogin', code) + window.isAddGmail = false } // 配置数据