feat: google oauth

This commit is contained in:
Henry
2024-05-07 22:33:36 +01:00
parent 23faa66d48
commit 3cf20cfb38
12 changed files with 269 additions and 107 deletions

View File

@@ -19,35 +19,43 @@ export default async function handler(
const queryParams = req.query;
const token_hash = stringOrFirstString(queryParams.token_hash);
const type = stringOrFirstString(queryParams.type);
const code = stringOrFirstString(queryParams.code);
let next = "/error";
if (token_hash && type) {
let authRes;
if ((token_hash && type) ?? code) {
const db = createNextClient(req, res);
const { error, data } = await db.auth.verifyOtp({
type: type as EmailOtpType,
token_hash,
});
console.log({ error });
if (token_hash && type) {
authRes = await db.auth.verifyOtp({
type: type as EmailOtpType,
token_hash,
});
}
if (data.user?.id) {
const user = await db
if (code) {
authRes = await db.auth.exchangeCodeForSession(code);
}
const user = authRes?.data.user;
if (user?.id) {
const existingUser = await db
.from("user")
.select()
.eq("id", data.user.id)
.eq("id", user.id)
.limit(1)
.maybeSingle();
if (!user.data) {
await db
.from("user")
.insert({ id: data.user.id, email: data.user.email ?? "" });
if (!existingUser.data) {
await db.from("user").insert({ id: user.id, email: user.email ?? "" });
}
}
if (error) {
console.error(error);
if (authRes?.error) {
console.error(authRes.error);
} else {
next = stringOrFirstString(queryParams.next) ?? "/";
}

View File

@@ -0,0 +1,5 @@
import SignupView from "~/views/auth/signup";
export default function SignupPage() {
return <SignupView />;
}

View File

@@ -1,5 +0,0 @@
import VerifyView from "~/views/auth/verify";
export default function VerifyPage() {
return <VerifyView />;
}