-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(destory-session): testing destroy session for all devices using supabase #833
base: main
Are you sure you want to change the base?
Changes from all commits
f0262ea
a8e74ef
c9ab58f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- CreateTable | ||
CREATE TABLE "Session" ( | ||
"id" TEXT NOT NULL, | ||
"expires" TIMESTAMP(3), | ||
"userId" TEXT, | ||
"data" JSONB NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "Session_pkey" PRIMARY KEY ("id") | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
directUrl = env("DIRECT_URL") | ||
} | ||
|
||
|
@@ -159,7 +159,7 @@ model Tag { | |
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
|
||
//@@unique([lower(name), organizationId]) //prisma doesnt support case insensitive unique index yet | ||
//@@unique([lower(name), organizationId]) //prisma doesnt support case insensitive unique index yet | ||
} | ||
|
||
model Note { | ||
|
@@ -274,7 +274,7 @@ model Location { | |
|
||
assets Asset[] | ||
|
||
// @@unique([lower(name), organizationId]) //prisma doesnt support case insensitive unique index yet | ||
// @@unique([lower(name), organizationId]) //prisma doesnt support case insensitive unique index yet | ||
} | ||
|
||
// Master data for roles | ||
|
@@ -297,17 +297,17 @@ model TeamMember { | |
id String @id @unique @default(cuid()) | ||
name String | ||
|
||
organization Organization @relation(fields: [organizationId], references: [id], onUpdate: Cascade) | ||
organizationId String | ||
organization Organization @relation(fields: [organizationId], references: [id], onUpdate: Cascade) | ||
organizationId String | ||
custodies Custody[] | ||
receivedInvites Invite[] | ||
user User? @relation(fields: [userId], references: [id], onUpdate: Cascade) | ||
user User? @relation(fields: [userId], references: [id], onUpdate: Cascade) | ||
userId String? | ||
|
||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
deletedAt DateTime? | ||
bookings Booking[] | ||
bookings Booking[] | ||
} | ||
|
||
model Custody { | ||
|
@@ -550,13 +550,13 @@ model Booking { | |
name String | ||
status BookingStatus @default(DRAFT) | ||
|
||
activeSchedulerReference String? | ||
activeSchedulerReference String? | ||
|
||
// Relationships | ||
creator User @relation("creator", fields: [creatorId], references: [id], onDelete: Cascade, onUpdate: Cascade) | ||
creatorId String | ||
|
||
custodianUser User? @relation("custodian", fields: [custodianUserId], references: [id], onDelete: Cascade, onUpdate: Cascade) | ||
custodianUser User? @relation("custodian", fields: [custodianUserId], references: [id], onDelete: Cascade, onUpdate: Cascade) | ||
custodianUserId String? | ||
|
||
custodianTeamMember TeamMember? @relation(fields: [custodianTeamMemberId], references: [id], onDelete: Cascade, onUpdate: Cascade) | ||
|
@@ -573,3 +573,14 @@ model Booking { | |
from DateTime? @db.Timestamptz(3) | ||
to DateTime? @db.Timestamptz(3) | ||
} | ||
|
||
model Session { | ||
id String @id @default(cuid()) | ||
|
||
expires DateTime? | ||
userId String? | ||
data Json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: normalise instead of hiding in a JSONB col? Given the schema below: email: z.string(),
userId: z.string(),
expiresAt: z.number(),
expiresIn: z.number(),
accessToken: z.string(),
refreshToken: z.string(), we could have a col for: Later in the |
||
|
||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import Input from "~/components/forms/input"; | |
import { Button } from "~/components/shared/button"; | ||
import PasswordResetForm from "~/components/user/password-reset-form"; | ||
import ProfilePicture from "~/components/user/profile-picture"; | ||
import { db } from "~/database"; | ||
|
||
import { useUserData } from "~/hooks"; | ||
import { sendResetPasswordLink } from "~/modules/auth"; | ||
|
@@ -48,22 +49,33 @@ export async function action({ context, request }: ActionFunctionArgs) { | |
if (formData.get("intent") === "resetPassword") { | ||
const email = formData.get("email") as string; | ||
|
||
const { error } = await sendResetPasswordLink(email); | ||
const data = await db.session.findMany({ | ||
where: { userId: authSession.userId }, | ||
}); | ||
|
||
if (error) { | ||
return json( | ||
{ | ||
message: "Unable to send password reset link", | ||
email: null, | ||
}, | ||
{ status: 500 } | ||
); | ||
} | ||
const updatedData = await db.session.updateMany({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we delete all existing sessions for this userId and then create a new one + save it in the context before redirect? |
||
where: { id: { in: data.map((item) => item.id) } }, | ||
data: { data: {}, userId: null, expires: null }, | ||
}); | ||
|
||
console.log(updatedData); | ||
|
||
// const { error } = await sendResetPasswordLink(email); | ||
|
||
// if (error) { | ||
// return json( | ||
// { | ||
// message: "Unable to send password reset link", | ||
// email: null, | ||
// }, | ||
// { status: 500 } | ||
// ); | ||
// } | ||
|
||
/** Logout user after 3 seconds */ | ||
await delay(2000); | ||
context.destroySession(); | ||
return redirect("/login"); | ||
// await delay(2000); | ||
// context.destroySession(); | ||
return redirect("/settings/account"); | ||
} | ||
|
||
/** Handle the use update */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about User link here to prevent phantom userId?