You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
430 B
TypeScript

import { RequestCookie } from 'next/dist/compiled/@edge-runtime/cookies'
import { db } from './db'
export const getUser = async (token: RequestCookie | undefined) => {
if (!token) return null
const existing_session = await db.query.sessions.findFirst({
where: (session, { eq }) => eq(session.sessionToken, token.value),
with: {
user: true,
},
})
if (!existing_session) return null
return existing_session.user
}