MCPcopy
hub / github.com/nextjs/saas-starter / getUser

Function getUser

lib/db/queries.ts:7–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import { verifyToken } from '@/lib/auth/session';
6
7export async function getUser() {
8 const sessionCookie = (await cookies()).get('session');
9 if (!sessionCookie || !sessionCookie.value) {
10 return null;
11 }
12
13 const sessionData = await verifyToken(sessionCookie.value);
14 if (
15 !sessionData ||
16 !sessionData.user ||
17 typeof sessionData.user.id !== 'number'
18 ) {
19 return null;
20 }
21
22 if (new Date(sessionData.expires) < new Date()) {
23 return null;
24 }
25
26 const user = await db
27 .select()
28 .from(users)
29 .where(and(eq(users.id, sessionData.user.id), isNull(users.deletedAt)))
30 .limit(1);
31
32 if (user.length === 0) {
33 return null;
34 }
35
36 return user[0];
37}
38
39export async function getTeamByStripeCustomerId(customerId: string) {
40 const result = await db

Callers 8

validatedActionWithUserFunction · 0.90
withTeamFunction · 0.90
createCheckoutSessionFunction · 0.90
RootLayoutFunction · 0.90
signOutFunction · 0.90
GETFunction · 0.90
getActivityLogsFunction · 0.85
getTeamForUserFunction · 0.85

Calls 1

verifyTokenFunction · 0.90

Tested by

no test coverage detected