fix: github登录无法将用户数据插入数据库
This commit is contained in:
parent
478d228313
commit
65db119a9a
|
@ -1,7 +1,26 @@
|
|||
"use client";
|
||||
import { insertUserProfile } from "@/utils/supabase/supabaseutils";
|
||||
import { createClient } from "@/utils/supabase/client";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export function SignInGitHub() {
|
||||
useEffect(() => {
|
||||
const supabase = createClient();
|
||||
const { data: data } = supabase.auth.onAuthStateChange(
|
||||
async (event, session) => {
|
||||
if (event === "SIGNED_IN") {
|
||||
// 用户登录成功,执行后续操作
|
||||
await insertUserProfile(session!.user, supabase);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
// call unsubscribe to remove the callback
|
||||
data.subscription.unsubscribe();
|
||||
};
|
||||
}, []);
|
||||
|
||||
const signInWithGithub = async () => {
|
||||
const supabase = createClient();
|
||||
const { data, error } = await supabase.auth.signInWithOAuth({
|
||||
|
|
|
@ -182,7 +182,7 @@ export async function insertUserProfile(data: any, supabase: SupabaseClient) {
|
|||
if (user) {
|
||||
const { data, error: profileError } = await supabase
|
||||
.from("profiles")
|
||||
.insert([{ id: user.id, email: user.email }]);
|
||||
.upsert([{ id: user.id, email: user.email }]);
|
||||
|
||||
if (profileError) {
|
||||
console.error("Failed to create user profile:", profileError);
|
||||
|
|
Loading…
Reference in New Issue
Block a user