This commit is contained in:
Saatvik Arya 2024-07-23 15:21:43 -07:00
parent 9e1687a1c1
commit 2569f6ce4e
4 changed files with 35 additions and 35 deletions

View file

@ -22,13 +22,13 @@ export default function Home() {
const { push } = useRouter();
useEffect(() => {
const updateDb = async () => {
await completeOnboarding();
}
const updateDb = async () => {
await completeOnboarding();
}
if (currStep > 3) {
updateDb().then(() => {
push("/home?q=what%20is%20supermemory");
});
updateDb().then(() => {
push("/home?q=what%20is%20supermemory");
});
}
}, [currStep]);
@ -385,11 +385,11 @@ function StepTwo({ currStep }: { currStep: number }) {
}
function Navbar() {
const router = useRouter();
const handleSkip = async () => {
await completeOnboarding();
router.push("/home?q=what%20is%20supermemory");
}
const router = useRouter();
const handleSkip = async () => {
await completeOnboarding();
router.push("/home?q=what%20is%20supermemory");
}
return (
<div className="flex items-center justify-between p-4 fixed top-0 left-0 w-full">
@ -399,7 +399,7 @@ function Navbar() {
className="hover:brightness-125 duration-200 size-12"
/>
<button className="text-sm" onClick={handleSkip}>Skip</button>
<button className="text-sm" onClick={handleSkip}>Skip</button>
</div>
);
}

View file

@ -24,26 +24,26 @@ import { redirect } from "next/navigation";
import { tweetToMd } from "@repo/shared-types/utils";
export const completeOnboarding = async (): ServerActionReturnType<boolean> => {
const data = await auth();
const data = await auth();
if (!data || !data.user || !data.user.id) {
redirect("/signin");
return { error: "Not authenticated", success: false };
}
if (!data || !data.user || !data.user.id) {
redirect("/signin");
return { error: "Not authenticated", success: false };
}
try {
const res = await db
.update(users)
.set({ hasOnboarded: true })
.where(eq(users.id, data.user.id))
try {
const res = await db
.update(users)
.set({ hasOnboarded: true })
.where(eq(users.id, data.user.id))
.returning({ hasOnboarded: users.hasOnboarded });
if (res.length === 0 || !res[0]?.hasOnboarded) {
return { success: false, data: false, error: "Failed to update user" };
}
return { success: true, data: res[0].hasOnboarded };
} catch (e) {
return { success: true, data: res[0].hasOnboarded };
} catch (e) {
return { success: false, data: false, error: (e as Error).message };
}

View file

@ -24,19 +24,19 @@ import { redirect } from "next/navigation";
import { cookies, headers } from "next/headers";
export const getUser = async (): ServerActionReturnType<User> => {
const data = await auth();
const data = await auth();
if (!data || !data.user || !data.user.id) {
redirect("/signin");
return { error: "Not authenticated", success: false };
}
if (!data || !data.user || !data.user.id) {
redirect("/signin");
return { error: "Not authenticated", success: false };
}
console.log("data.user.id", data.user.id);
const user = await db.query.users.findFirst({
where: eq(users.id, data.user.id),
});
console.log("data.user.id", data.user.id);
const user = await db.query.users.findFirst({
where: eq(users.id, data.user.id),
});
return { success: true, data: user };
return { success: true, data: user };
};
export const getSpaces = async (): ServerActionReturnType<StoredSpace[]> => {

View file

@ -22,7 +22,7 @@ export const users = createTable(
emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
image: text("image"),
telegramId: text("telegramId"),
hasOnboarded: integer("hasOnboarded", { mode: "boolean" }).default(false),
hasOnboarded: integer("hasOnboarded", { mode: "boolean" }).default(false),
},
(user) => ({
emailIdx: index("users_email_idx").on(user.email),