Skip to content

Commit

Permalink
refactor(site-header): improve authentication flow and error handling…
Browse files Browse the repository at this point in the history
… when loading user session and profile
  • Loading branch information
JaleelB committed Aug 23, 2024
1 parent 2e6eede commit 8be519c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const Icons = {
{..._props}
stroke="currentColor"
fill="currentColor"
stroke-width="0"
strokeWidth="0"
viewBox="0 0 488 512"
height="1em"
width="1em"
Expand Down
17 changes: 10 additions & 7 deletions components/site-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@ import { getUser } from "@/data-access/users";
import Nav from "./nav";
import { Profile, User } from "@/server/db/schema";
import { getUserProfileUseCase } from "@/use-cases/users";
import { redirect } from "next/navigation";

export type UserInfo =
| { id: number; email: string | null; emailVerified: Date | null }
| null
| undefined;

async function SiteHeader() {
let userSession = await getCurrentUser();
let user: User | undefined = undefined;
let profile: Profile | undefined = undefined;
const userSession = await getCurrentUser();

if (!userSession) {
user = undefined;
redirect("/signin");
}

if (userSession) {
user = await getUser(userSession.id);
profile = await getUserProfileUseCase(userSession.id);
const [user, profile] = await Promise.all([
getUser(userSession.id),
getUserProfileUseCase(userSession.id),
]);

if (!user || !profile) {
redirect("/signin");
}

return <Nav user={user} profile={profile as Profile} />;
Expand Down

0 comments on commit 8be519c

Please sign in to comment.