Skip to content

Commit

Permalink
fix: make Session functions more type-safe (remix-run#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey authored Jun 8, 2022
1 parent 13e191e commit 78c04cb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/session.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createCookieSessionStorage, redirect } from "@remix-run/node";
import invariant from "tiny-invariant";

import type { User } from "~/models/user.server";
import { getUserById } from "~/models/user.server";

invariant(process.env.SESSION_SECRET, "SESSION_SECRET must be set");
Expand All @@ -24,7 +25,9 @@ export async function getSession(request: Request) {
return sessionStorage.getSession(cookie);
}

export async function getUserId(request: Request): Promise<string | undefined> {
export async function getUserId(
request: Request
): Promise<User["id"] | undefined> {
const session = await getSession(request);
const userId = session.get(USER_SESSION_KEY);
return userId;
Expand Down

0 comments on commit 78c04cb

Please sign in to comment.