修复google登录

This commit is contained in:
liangzai 2024-09-18 23:42:50 +08:00
parent 4ef7232260
commit 8028fa6f5f

View File

@ -9,28 +9,34 @@ export default function GoogleLogin() {
const googleLogin = async (method: string) => {
setLoading(true); // 开始请求时设置 loading 为 true
try {
const response = await fetch("/oauth2callback/google/login/", {
method: method,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
});
console.log("response", response);
if (response.ok) {
console.log("Success:", response);
window.location.href = response.url;
// 处理成功响应
} else {
console.error("Failed:", response.status);
// 处理失败响应
}
} catch (error) {
console.error("Error:", error);
// 处理请求错误
} finally {
setLoading(false); // 请求结束后设置 loading 为 false
}
const form = document.createElement("form");
form.method = "POST";
form.action = "/oauth2callback/google/login/";
document.body.appendChild(form);
form.submit(); // 提交表单
// try {
// const response = await fetch("/oauth2callback/google/login/", {
// method: method,
// headers: {
// "Content-Type": "application/x-www-form-urlencoded",
// },
// });
// console.log("response", response);
// if (response.ok) {
// console.log("Success:", response);
// window.location.href = response.url;
// // 处理成功响应
// } else {
// console.error("Failed:", response.status);
// // 处理失败响应
// }
// } catch (error) {
// console.error("Error:", error);
// // 处理请求错误
// } finally {
// setLoading(false); // 请求结束后设置 loading 为 false
// }
};
return (