Conversation
6b793df to
5d3e01f
Compare
| * @returns The session | ||
| */ | ||
| export async function getSession(id: string) { | ||
| const session = await prisma.session.findUnique({ |
There was a problem hiding this comment.
can we make funcs like this inline more?
| }, | ||
| }, | ||
| }); | ||
| } No newline at end of file |
There was a problem hiding this comment.
new line at end of file pls
| * @returns If the delete was successful | ||
| */ | ||
| export async function deleteSession(id: string) { | ||
| return prisma.session.delete({ |
There was a problem hiding this comment.
inline with this too, anything that is simple enough to go inline
|
|
||
| export type UpdateSessionData = { | ||
| expiresAt?: Date; | ||
| }; No newline at end of file |
| @@ -0,0 +1,8 @@ | |||
| export type GetSessionsFilters = { | |||
There was a problem hiding this comment.
I'm not sure that these types are complex enough to warrant an externally defined type. Can we just do this inline on the functions that use them?
There was a problem hiding this comment.
I was having this be outside incase we wanna expand on it in the future, i can just leave it in the file if that's better
| * @param filters userId and projectId | ||
| * @returns All sessions associated with the filters | ||
| */ | ||
| export async function getSessions(filters: GetSessionsFilters) { |
There was a problem hiding this comment.
what is the use case for this function and should both params be optional? Or should we require at least one? Or should both be required?
There was a problem hiding this comment.
Youre right, ill make both required
| return crypto.createHash("sha256").update(token).digest("hex"); | ||
| } | ||
|
|
||
| export type GetSessionsFilters = { |
There was a problem hiding this comment.
I think these should be defined inline with the function
| * @param id The session id | ||
| * @returns The session | ||
| */ | ||
| export const getSession = async (id: string) => |
There was a problem hiding this comment.
ah, I would define this with function as regular since defining it as a const makes it different than the rest
| if (!session) return null; | ||
|
|
||
| // don't extend expired sessions | ||
| if (session.expiresAt < new Date()) { |
There was a problem hiding this comment.
similar to above, can make this part of prisma query
There was a problem hiding this comment.
Apparently prisma doesnt support that, i think this should be fine
| } | ||
| return prisma.session.update({ | ||
| where: { id }, | ||
| data: { |
| * @param id The session id | ||
| * @returns If the delete was successful | ||
| */ | ||
| export const deleteSession = async (id: string) => |
Created lib/session.ts for managing the Session join table which contains:
createSession
getSession
getSessions
deleteSession
validateSession