Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
fix: minor
Browse files Browse the repository at this point in the history
  • Loading branch information
KunalSin9h committed May 24, 2024
1 parent 8866e9a commit fa5ffb0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
9 changes: 1 addition & 8 deletions src/components/User.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { getUserFromCookie } from "~/server-function";
import { UserType } from "../../db/schema";

export default function User() {
let user: UserType | null = null;

try {
user = getUserFromCookie();
} catch (e) {
console.log(e);
}
let user = getUserFromCookie();

if (!user) {
return (
Expand Down
12 changes: 9 additions & 3 deletions src/server-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import { UserType } from "../db/schema";
export const AUTH_USER_DATA = "user-data";
export const AUTH_TOKEN = "auth-token";

export function getUserFromCookie(): UserType {
export function getUserFromCookie(): UserType | null {
"use server";
const user = getCookie(AUTH_USER_DATA);

if (!user) {
throw new Error("not user data in cookie");
return null;
}

return JSON.parse(user);
try {
const u: UserType = JSON.parse(user);
return u;
} catch (e) {
console.log(e);
return null;
}
}

0 comments on commit fa5ffb0

Please sign in to comment.