Skip to content

AUTH-10 Create session actions#6

Open
jakewc12 wants to merge 1 commit intomainfrom
auth-10
Open

AUTH-10 Create session actions#6
jakewc12 wants to merge 1 commit intomainfrom
auth-10

Conversation

@jakewc12
Copy link
Copy Markdown
Collaborator

@jakewc12 jakewc12 commented Apr 7, 2026

Created lib/session.ts for managing the Session join table which contains:

createSession
getSession
getSessions
deleteSession
validateSession

@jakewc12 jakewc12 force-pushed the auth-10 branch 2 times, most recently from 6b793df to 5d3e01f Compare April 7, 2026 02:48
Copy link
Copy Markdown
Owner

@SGAOperations SGAOperations left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few things!

Comment thread src/lib/session.ts.ts Outdated
* @returns The session
*/
export async function getSession(id: string) {
const session = await prisma.session.findUnique({
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make funcs like this inline more?

Comment thread src/lib/session.ts.ts Outdated
},
},
});
} No newline at end of file
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line at end of file pls

Comment thread src/lib/session.ts.ts Outdated
* @returns If the delete was successful
*/
export async function deleteSession(id: string) {
return prisma.session.delete({
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline with this too, anything that is simple enough to go inline

Comment thread src/types/session.type.ts Outdated

export type UpdateSessionData = {
expiresAt?: Date;
}; No newline at end of file
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line end of file pls

Comment thread src/types/session.type.ts Outdated
@@ -0,0 +1,8 @@
export type GetSessionsFilters = {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/lib/session.ts.ts Outdated
* @param filters userId and projectId
* @returns All sessions associated with the filters
*/
export async function getSessions(filters: GetSessionsFilters) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Youre right, ill make both required

Comment thread src/lib/session.ts Outdated
return crypto.createHash("sha256").update(token).digest("hex");
}

export type GetSessionsFilters = {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should be defined inline with the function

Comment thread src/lib/session.ts Outdated
* @param id The session id
* @returns The session
*/
export const getSession = async (id: string) =>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I would define this with function as regular since defining it as a const makes it different than the rest

Comment thread src/lib/session.ts Outdated
if (!session) return null;

// don't extend expired sessions
if (session.expiresAt < new Date()) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to above, can make this part of prisma query

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently prisma doesnt support that, i think this should be fine

Comment thread src/lib/session.ts Outdated
}
return prisma.session.update({
where: { id },
data: {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be inline

Comment thread src/lib/session.ts Outdated
* @param id The session id
* @returns If the delete was successful
*/
export const deleteSession = async (id: string) =>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same not as prev func

@jakewc12 jakewc12 changed the title ATM-10 Create session actions AUTH-10 Create session actions Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants