Skip to content
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

Restrict access to other user conversations #32

Merged
merged 5 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ entity User {=psl

externalAuthAssociations SocialLogin[]
chats Chat[]
conversations Conversation[]
psl=}
// relatedObject RelatedObject[] - add in line 86
entity SocialLogin {=psl
Expand Down Expand Up @@ -130,6 +131,8 @@ entity Conversation {=psl
updatedAt DateTime @updatedAt
chat Chat? @relation(fields: [chatId], references: [id])
chatId Int?
user User? @relation(fields: [userId], references: [id])
userId Int?
psl=}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "Conversation" ADD COLUMN "userId" INTEGER;

-- AddForeignKey
ALTER TABLE "Conversation" ADD CONSTRAINT "Conversation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
1 change: 1 addition & 0 deletions src/server/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export const createChat: CreateChat<void, Conversation> = async (_args, context)
},
],
chat: { connect: { id: chat.id } },
user: { connect: { id: context.user.id } },
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const getConversations: GetConversations<GetConversationPayload, Conversa
throw new HttpError(401);
}
return context.entities.Conversation.findFirstOrThrow({
where: { chatId: args.chatId },
where: { chatId: args.chatId, userId: context.user.id },
})
}

Expand Down
Loading