Initial commit
This commit is contained in:
parent
bfa30aa504
commit
93aad0a8f8
|
@ -70,7 +70,7 @@ async function getUserPageProps(context: GetStaticPropsContext) {
|
|||
const { type: slug, user: username } = paramsSchema.parse(context.params);
|
||||
const ssg = await ssgInit(context);
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
/** TODO: We should standarize this */
|
||||
username: username.toLowerCase().replace(/( |%20)/g, "+"),
|
||||
|
|
|
@ -18,7 +18,7 @@ export const getStaticProps: GetStaticProps<
|
|||
{ user: string }
|
||||
> = async (context) => {
|
||||
const { user: username, month } = paramsSchema.parse(context.params);
|
||||
const userWithCredentials = await prisma.user.findUnique({
|
||||
const userWithCredentials = await prisma.user.findFirst({
|
||||
where: {
|
||||
username,
|
||||
},
|
||||
|
|
|
@ -18,7 +18,7 @@ async function getIdentityData(req: NextApiRequest) {
|
|||
const { username, teamname } = querySchema.parse(req.query);
|
||||
|
||||
if (username) {
|
||||
const user = await prisma.user.findUnique({
|
||||
const user = await prisma.user.findFirst({
|
||||
where: { username },
|
||||
select: { avatar: true, email: true },
|
||||
});
|
||||
|
|
|
@ -69,7 +69,7 @@ const providers: Provider[] = [
|
|||
throw new Error(ErrorCode.InternalServerError);
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
email: credentials.email.toLowerCase(),
|
||||
},
|
||||
|
@ -605,7 +605,12 @@ export const AUTH_OPTIONS: AuthOptions = {
|
|||
!existingUserWithEmail.username
|
||||
) {
|
||||
await prisma.user.update({
|
||||
where: { email: existingUserWithEmail.email },
|
||||
where: {
|
||||
email_username: {
|
||||
email: existingUserWithEmail.email,
|
||||
username: existingUserWithEmail.username!,
|
||||
},
|
||||
},
|
||||
data: {
|
||||
// update the email to the IdP email
|
||||
email: user.email,
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[email,username]` on the table `users` will be added. If there are existing duplicate values, this will fail.
|
||||
- A unique constraint covering the columns `[username,organizationId]` on the table `users` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- DropIndex
|
||||
DROP INDEX "users_email_idx";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "users_username_key";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Team" ADD COLUMN "parentId" INTEGER;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "organizationId" INTEGER;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "users_email_username_key" ON "users"("email", "username");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "users_username_organizationId_key" ON "users"("username", "organizationId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Team"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Team" ADD CONSTRAINT "Team_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -166,10 +166,10 @@ enum UserPermissionRole {
|
|||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
username String? @unique
|
||||
username String?
|
||||
name String?
|
||||
/// @zod.email()
|
||||
email String @unique
|
||||
email String
|
||||
emailVerified DateTime?
|
||||
password String?
|
||||
bio String?
|
||||
|
@ -225,8 +225,16 @@ model User {
|
|||
routingForms App_RoutingForms_Form[] @relation("routing-form")
|
||||
verifiedNumbers VerifiedNumber[]
|
||||
hosts Host[]
|
||||
organizationId Int?
|
||||
organization Team? @relation("scope", fields: [organizationId], references: [id], onDelete: SetNull)
|
||||
// Linking account code for orgs v2
|
||||
//linkedByUserId Int?
|
||||
//linkedBy User? @relation("linked_account", fields: [linkedByUserId], references: [id], onDelete: Cascade)
|
||||
//linkedUsers User[] @relation("linked_account")*/
|
||||
|
||||
@@index([email])
|
||||
@@unique([email])
|
||||
@@unique([email, username])
|
||||
@@unique([username, organizationId])
|
||||
@@index([emailVerified])
|
||||
@@index([identityProvider])
|
||||
@@index([identityProviderId])
|
||||
|
@ -255,6 +263,10 @@ model Team {
|
|||
brandColor String @default("#292929")
|
||||
darkBrandColor String @default("#fafafa")
|
||||
verifiedNumbers VerifiedNumber[]
|
||||
parentId Int?
|
||||
parent Team? @relation("organization", fields: [parentId], references: [id], onDelete: Cascade)
|
||||
children Team[] @relation("organization")
|
||||
scopedMembers User[] @relation("scope")
|
||||
}
|
||||
|
||||
enum MembershipRole {
|
||||
|
|
|
@ -142,7 +142,10 @@ async function seedAppData() {
|
|||
],
|
||||
user: {
|
||||
connect: {
|
||||
username: "pro",
|
||||
email_username: {
|
||||
username: "pro",
|
||||
email: "pro@example.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
name: seededForm.name,
|
||||
|
|
|
@ -50,7 +50,7 @@ async function createUserAndEventType(opts: {
|
|||
};
|
||||
|
||||
const user = await prisma.user.upsert({
|
||||
where: { email: opts.user.email },
|
||||
where: { email_username: { email: opts.user.email, username: opts.user.username } },
|
||||
update: userData,
|
||||
create: userData,
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user