谷歌登录
This commit is contained in:
7
env.d.ts
vendored
7
env.d.ts
vendored
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
<button type="button" class="login-button" @click="handleConfirm">Sign Up</button>
|
||||
|
||||
<GoogleLogin text="Sign up with Google" @googelLogin="handleGoogleSignup" />
|
||||
<GoogleLogin text="Sign up with Google" @googelLogin="handleGoogleSignup" ref="googleSignupRef" @click="clickGooleLogin" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
// 配置数据
|
||||
|
||||
Reference in New Issue
Block a user