From b75b1d1c0de845e7d9e5d4f2c98e99c0ffff80ba Mon Sep 17 00:00:00 2001 From: David Alecrim Date: Tue, 19 Sep 2023 11:50:02 +0100 Subject: [PATCH] refactor: refactor clerk auth (#183) * feat: refactor clerk auth * feat: update clerk package --- package-lock.json | 63 ++++++++++++++++--- packages/api/package.json | 2 +- .../src/auth/guards/clerk/clerk.auth.guard.ts | 12 ++-- .../clerk/open-api-clerk-headers.decorator.ts | 1 - packages/web-ui/api/apiClient.ts | 3 - .../api/requests/ai-models/get-ai-model.ts | 2 - .../api/requests/ai-models/get-ai-models.ts | 6 +- .../web-ui/api/requests/rooms/create-room.ts | 2 - .../api/requests/rooms/delete-document.ts | 2 - .../web-ui/api/requests/rooms/delete-room.ts | 7 +-- .../web-ui/api/requests/rooms/get-chat.ts | 7 +-- .../web-ui/api/requests/rooms/get-my-rooms.ts | 6 +- .../api/requests/rooms/get-public-rooms.ts | 6 +- .../web-ui/api/requests/rooms/get-room.ts | 7 +-- .../api/requests/rooms/invite-user-to-room.ts | 2 - .../web-ui/api/requests/rooms/join-room.ts | 2 - .../web-ui/api/requests/rooms/leave-room.ts | 2 - .../web-ui/api/requests/rooms/update-room.ts | 2 - .../api/requests/rooms/upload-documents.ts | 2 - .../api/requests/users/get-all-users.ts | 6 +- .../web-ui/api/requests/users/get-user.ts | 2 - .../web-ui/api/requests/users/get-users.ts | 2 - packages/web-ui/app/rooms/[room]/layout.tsx | 8 +-- packages/web-ui/app/rooms/[room]/page.tsx | 8 +-- .../web-ui/app/rooms/[room]/settings/page.tsx | 10 +-- packages/web-ui/app/rooms/layout.tsx | 4 +- packages/web-ui/app/rooms/page.tsx | 4 +- packages/web-ui/components/chat-tools.tsx | 4 +- packages/web-ui/components/chat.tsx | 8 +-- .../web-ui/components/create-room-form.tsx | 4 +- packages/web-ui/components/delete-room.tsx | 4 +- .../components/document-upload-form.tsx | 4 +- packages/web-ui/components/leave-room.tsx | 4 +- .../web-ui/components/room-search-items.tsx | 4 +- packages/web-ui/components/rooms.tsx | 6 +- packages/web-ui/components/site-header.tsx | 8 +-- .../web-ui/components/update-room-form.tsx | 4 +- .../web-ui/components/user-search-items.tsx | 4 +- 38 files changed, 115 insertions(+), 119 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2aa1ddf..14e7163 100644 --- a/package-lock.json +++ b/package-lock.json @@ -754,11 +754,12 @@ } }, "node_modules/@clerk/clerk-sdk-node": { - "version": "4.12.1", - "license": "MIT", + "version": "4.12.5", + "resolved": "https://registry.npmjs.org/@clerk/clerk-sdk-node/-/clerk-sdk-node-4.12.5.tgz", + "integrity": "sha512-GW0eXhG2P7GCFKnc2j7zOAR2qK0fOQwoZAFvfovXJNyZhlcbg7NKtjsbW6Q8X7qrtaD2UX6SuOvuxQZP633H7w==", "dependencies": { - "@clerk/backend": "^0.26.0", - "@clerk/types": "^3.48.1", + "@clerk/backend": "^0.29.0", + "@clerk/types": "^3.51.0", "@types/cookies": "0.7.7", "@types/express": "4.17.14", "@types/node-fetch": "2.6.2", @@ -770,6 +771,37 @@ "node": ">=14" } }, + "node_modules/@clerk/clerk-sdk-node/node_modules/@clerk/backend": { + "version": "0.29.0", + "resolved": "https://registry.npmjs.org/@clerk/backend/-/backend-0.29.0.tgz", + "integrity": "sha512-2miuqyzmlzboTcLQOtafGw4+InnkFALMWjM9l9gu75KBWg1pUdFYLEDcJV+MHt0ZtY+pZO7aGnPE0Mf7QnG+bA==", + "dependencies": { + "@clerk/types": "^3.51.0", + "@peculiar/webcrypto": "1.4.1", + "@types/node": "16.18.6", + "cookie": "0.5.0", + "deepmerge": "4.2.2", + "node-fetch-native": "1.0.1", + "snakecase-keys": "5.4.4", + "tslib": "2.4.1" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/@clerk/clerk-sdk-node/node_modules/@clerk/backend/node_modules/snakecase-keys": { + "version": "5.4.4", + "resolved": "https://registry.npmjs.org/snakecase-keys/-/snakecase-keys-5.4.4.tgz", + "integrity": "sha512-YTywJG93yxwHLgrYLZjlC75moVEX04LZM4FHfihjHe1FCXm+QaLOFfSf535aXOAd0ArVQMWUAe8ZPm4VtWyXaA==", + "dependencies": { + "map-obj": "^4.1.0", + "snake-case": "^3.0.4", + "type-fest": "^2.5.2" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@clerk/clerk-sdk-node/node_modules/@types/express": { "version": "4.17.14", "license": "MIT", @@ -780,6 +812,22 @@ "@types/serve-static": "*" } }, + "node_modules/@clerk/clerk-sdk-node/node_modules/@types/node": { + "version": "16.18.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.6.tgz", + "integrity": "sha512-vmYJF0REqDyyU0gviezF/KHq/fYaUbFhkcNbQCuPGFQj6VTbXuHZoxs/Y7mutWe73C8AC6l9fFu8mSYiBAqkGA==" + }, + "node_modules/@clerk/clerk-sdk-node/node_modules/type-fest": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", + "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@clerk/nextjs": { "version": "4.23.1", "license": "MIT", @@ -813,8 +861,9 @@ } }, "node_modules/@clerk/types": { - "version": "3.48.1", - "license": "MIT", + "version": "3.51.0", + "resolved": "https://registry.npmjs.org/@clerk/types/-/types-3.51.0.tgz", + "integrity": "sha512-JCSG2W1nI+zEIyDTGKfQJkvl2Ve5vpR3AxDsyXQMf/aZyXhBT351W1dPUfUW4K9MpLmZ2sB/1gj3UJFaBw9e7g==", "dependencies": { "csstype": "3.1.1" }, @@ -16598,7 +16647,7 @@ "version": "1.0.0", "dependencies": { "@anatine/zod-nestjs": "^1.10.0", - "@clerk/clerk-sdk-node": "^4.12.1", + "@clerk/clerk-sdk-node": "^4.12.5", "@nestjs/bull": "^0.6.3", "@nestjs/common": "^9.0.0", "@nestjs/config": "^2.3.2", diff --git a/packages/api/package.json b/packages/api/package.json index aa13272..691a8a0 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "@anatine/zod-nestjs": "^1.10.0", - "@clerk/clerk-sdk-node": "^4.12.1", + "@clerk/clerk-sdk-node": "^4.12.5", "@nestjs/bull": "^0.6.3", "@nestjs/common": "^9.0.0", "@nestjs/config": "^2.3.2", diff --git a/packages/api/src/auth/guards/clerk/clerk.auth.guard.ts b/packages/api/src/auth/guards/clerk/clerk.auth.guard.ts index 9236f69..b773781 100644 --- a/packages/api/src/auth/guards/clerk/clerk.auth.guard.ts +++ b/packages/api/src/auth/guards/clerk/clerk.auth.guard.ts @@ -1,7 +1,7 @@ import 'dotenv/config'; import { UserUnauthorizedException } from '@/auth/exceptions/user-unauthorized.exception'; import { AuthGuard } from '@/auth/guards/auth-guard'; -import { sessions } from '@clerk/clerk-sdk-node'; +import { clerkClient } from '@clerk/clerk-sdk-node'; import { ExecutionContext, Injectable, Logger } from '@nestjs/common'; import { Request } from 'express'; @@ -12,13 +12,15 @@ export class ClerkAuthGuard extends AuthGuard { async canActivate(context: ExecutionContext): Promise { const request: Request = context.switchToHttp().getRequest(); const clerkJwtToken = request.get('x-clerk-jwt-token'); - const clerkSessionId = request.get('x-clerk-session-id'); return new Promise((resolve, reject) => { - sessions - .verifySession(clerkSessionId, clerkJwtToken) + clerkClient + .authenticateRequest({ + loadSession: true, + headerToken: clerkJwtToken, + }) .then((session) => { - request['auth'] = session; + request['auth'] = session.toAuth().session; resolve(true); }) .catch((e) => { diff --git a/packages/api/src/auth/guards/clerk/open-api-clerk-headers.decorator.ts b/packages/api/src/auth/guards/clerk/open-api-clerk-headers.decorator.ts index e668348..f2ae498 100644 --- a/packages/api/src/auth/guards/clerk/open-api-clerk-headers.decorator.ts +++ b/packages/api/src/auth/guards/clerk/open-api-clerk-headers.decorator.ts @@ -3,7 +3,6 @@ import { ApiHeader } from '@nestjs/swagger'; export function ApiClerkAuthHeaders(): MethodDecorator { return applyDecorators( - ApiHeader({ name: 'x-clerk-session-id', required: true }), ApiHeader({ name: 'x-clerk-jwt-token', required: true }) ); } diff --git a/packages/web-ui/api/apiClient.ts b/packages/web-ui/api/apiClient.ts index 75a8c34..f98b9ee 100644 --- a/packages/web-ui/api/apiClient.ts +++ b/packages/web-ui/api/apiClient.ts @@ -1,7 +1,6 @@ export type ClerkFetcherParamsType = { url: string; options?: RequestInit; - sessionId: string | null; jwtToken: string | null; isApplicationJson?: boolean; }; @@ -19,7 +18,6 @@ const myFetch = createFetch( async function apiClient({ url, options, - sessionId, jwtToken, isApplicationJson = true, }: ClerkFetcherParamsType) { @@ -27,7 +25,6 @@ async function apiClient({ ...options, headers: { ...(isApplicationJson ? { 'Content-Type': 'application/json' } : {}), - 'X-Clerk-Session-Id': sessionId ?? '', 'X-Clerk-Jwt-Token': jwtToken ?? '', ...options?.headers, }, diff --git a/packages/web-ui/api/requests/ai-models/get-ai-model.ts b/packages/web-ui/api/requests/ai-models/get-ai-model.ts index e954b11..5040277 100644 --- a/packages/web-ui/api/requests/ai-models/get-ai-model.ts +++ b/packages/web-ui/api/requests/ai-models/get-ai-model.ts @@ -6,14 +6,12 @@ export const GET_AI_MODEL_REQ_KEY = 'ai-model'; export const getAiModel = async ( aiModelId: string, - sessionId: string | null, jwtToken: string | null ) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.ai.getAiModel(aiModelId), options: { method: 'GET' }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/ai-models/get-ai-models.ts b/packages/web-ui/api/requests/ai-models/get-ai-models.ts index 179b7ba..a801653 100644 --- a/packages/web-ui/api/requests/ai-models/get-ai-models.ts +++ b/packages/web-ui/api/requests/ai-models/get-ai-models.ts @@ -4,15 +4,11 @@ import { AiModelResponseDto } from '@/contract/ai/ai-model.response.dto.d'; export const GET_AI_MODELS_REQ_KEY = 'ai-models'; -export const getAiModels = async ( - sessionId: string | null, - jwtToken: string | null -) => { +export const getAiModels = async (jwtToken: string | null) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.ai.getAiModels(), options: { method: 'GET' }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/rooms/create-room.ts b/packages/web-ui/api/requests/rooms/create-room.ts index fcea8ef..12e89a6 100644 --- a/packages/web-ui/api/requests/rooms/create-room.ts +++ b/packages/web-ui/api/requests/rooms/create-room.ts @@ -5,14 +5,12 @@ import { RoomResponseDto } from '@/contract/rooms/room.response.dto.d'; export const createRoom = async ( values: CreateRoomRequestDto, - sessionId: string | null, jwtToken: string | null ) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.rooms.createRoom(), options: { method: 'POST', body: JSON.stringify(values) }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/rooms/delete-document.ts b/packages/web-ui/api/requests/rooms/delete-document.ts index f60561d..9938957 100644 --- a/packages/web-ui/api/requests/rooms/delete-document.ts +++ b/packages/web-ui/api/requests/rooms/delete-document.ts @@ -6,14 +6,12 @@ import { RemoveDocumentFromChatRequestDto } from '@/contract/chats/remove-docume export const deleteDocument = async ( roomId: string, values: RemoveDocumentFromChatRequestDto, - sessionId: string | null, jwtToken: string | null ) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.chats.deleteDocument(roomId), options: { method: 'PATCH', body: JSON.stringify(values) }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/rooms/delete-room.ts b/packages/web-ui/api/requests/rooms/delete-room.ts index d1dcb34..225971d 100644 --- a/packages/web-ui/api/requests/rooms/delete-room.ts +++ b/packages/web-ui/api/requests/rooms/delete-room.ts @@ -1,16 +1,11 @@ import { apiClient } from '@/api/apiClient'; import Endpoints from '@/api/endpoints'; -export const deleteRoom = async ( - roomId: string, - sessionId: string | null, - jwtToken: string | null -) => { +export const deleteRoom = async (roomId: string, jwtToken: string | null) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.rooms.deleteRoom(roomId), options: { method: 'DELETE' }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/rooms/get-chat.ts b/packages/web-ui/api/requests/rooms/get-chat.ts index afcaf38..94a0ec0 100644 --- a/packages/web-ui/api/requests/rooms/get-chat.ts +++ b/packages/web-ui/api/requests/rooms/get-chat.ts @@ -4,16 +4,11 @@ import { ChatResponseDto } from '@/contract/chats/chat.response.dto.d'; export const GET_CHAT_REQ_KEY = 'chat'; -export const getChat = async ( - roomId: string, - sessionId: string | null, - jwtToken: string | null -) => { +export const getChat = async (roomId: string, jwtToken: string | null) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.chats.getChat(roomId), options: { method: 'GET' }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/rooms/get-my-rooms.ts b/packages/web-ui/api/requests/rooms/get-my-rooms.ts index ca8a1df..b740e3a 100644 --- a/packages/web-ui/api/requests/rooms/get-my-rooms.ts +++ b/packages/web-ui/api/requests/rooms/get-my-rooms.ts @@ -4,15 +4,11 @@ import { RoomResponseDto } from '@/contract/rooms/room.response.dto.d'; export const GET_MY_ROOMS_REQ_KEY = 'my-rooms'; -export const getMyRooms = async ( - sessionId: string | null, - jwtToken: string | null -) => { +export const getMyRooms = async (jwtToken: string | null) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.rooms.getMyRooms(), options: { method: 'GET' }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/rooms/get-public-rooms.ts b/packages/web-ui/api/requests/rooms/get-public-rooms.ts index 76d4b49..9f0f58a 100644 --- a/packages/web-ui/api/requests/rooms/get-public-rooms.ts +++ b/packages/web-ui/api/requests/rooms/get-public-rooms.ts @@ -4,15 +4,11 @@ import { RoomResponseDto } from '@/contract/rooms/room.response.dto.d'; export const GET_PUBLIC_ROOMS_REQ_KEY = 'public-rooms'; -export const getPublicRooms = async ( - sessionId: string | null, - jwtToken: string | null -) => { +export const getPublicRooms = async (jwtToken: string | null) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.rooms.getPublicRooms(), options: { method: 'GET' }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/rooms/get-room.ts b/packages/web-ui/api/requests/rooms/get-room.ts index 0480870..5e7367b 100644 --- a/packages/web-ui/api/requests/rooms/get-room.ts +++ b/packages/web-ui/api/requests/rooms/get-room.ts @@ -4,16 +4,11 @@ import { RoomResponseDto } from '@/contract/rooms/room.response.dto.d'; export const GET_ROOM_REQ_KEY = 'room'; -export const getRoom = async ( - roomId: string, - sessionId: string | null, - jwtToken: string | null -) => { +export const getRoom = async (roomId: string, jwtToken: string | null) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.rooms.getRoomById(roomId), options: { method: 'GET', cache: 'no-store' }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/rooms/invite-user-to-room.ts b/packages/web-ui/api/requests/rooms/invite-user-to-room.ts index 1a70e4e..df1c71d 100644 --- a/packages/web-ui/api/requests/rooms/invite-user-to-room.ts +++ b/packages/web-ui/api/requests/rooms/invite-user-to-room.ts @@ -5,14 +5,12 @@ import { RoomResponseDto } from '@/contract/rooms/room.response.dto.d'; export const inviteUserToRoom = async ( values: InviteUserToRoomRequestDto, - sessionId: string | null, jwtToken: string | null ) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.rooms.inviteToRoom(), options: { method: 'POST', body: JSON.stringify(values) }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/rooms/join-room.ts b/packages/web-ui/api/requests/rooms/join-room.ts index 6033259..ccee7b9 100644 --- a/packages/web-ui/api/requests/rooms/join-room.ts +++ b/packages/web-ui/api/requests/rooms/join-room.ts @@ -5,14 +5,12 @@ import { RoomResponseDto } from '@/contract/rooms/room.response.dto.d'; export const joinRoom = async ( values: JoinRoomRequestDto, - sessionId: string | null, jwtToken: string | null ) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.rooms.joinRoom(), options: { method: 'POST', body: JSON.stringify(values) }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/rooms/leave-room.ts b/packages/web-ui/api/requests/rooms/leave-room.ts index 9273287..4d142d7 100644 --- a/packages/web-ui/api/requests/rooms/leave-room.ts +++ b/packages/web-ui/api/requests/rooms/leave-room.ts @@ -5,14 +5,12 @@ import { RoomResponseDto } from '@/contract/rooms/room.response.dto.d'; export const leaveRoom = async ( values: LeaveRoomRequestDto, - sessionId: string | null, jwtToken: string | null ) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.rooms.leaveRoom(), options: { method: 'POST', body: JSON.stringify(values) }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/rooms/update-room.ts b/packages/web-ui/api/requests/rooms/update-room.ts index a1ab8e2..6cdd479 100644 --- a/packages/web-ui/api/requests/rooms/update-room.ts +++ b/packages/web-ui/api/requests/rooms/update-room.ts @@ -6,14 +6,12 @@ import { UpdateRoomSettingsRequestDto } from '@/contract/rooms/update-room-setti export const updateRoom = async ( roomId: string, values: UpdateRoomSettingsRequestDto, - sessionId: string | null, jwtToken: string | null ) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.rooms.updateRoom(roomId), options: { method: 'PATCH', body: JSON.stringify(values) }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/rooms/upload-documents.ts b/packages/web-ui/api/requests/rooms/upload-documents.ts index a6b22e2..2af9416 100644 --- a/packages/web-ui/api/requests/rooms/upload-documents.ts +++ b/packages/web-ui/api/requests/rooms/upload-documents.ts @@ -4,7 +4,6 @@ import Endpoints from '@/api/endpoints'; export const uploadDocuments = async ( roomId: string, formData: FormData, - sessionId: string | null, jwtToken: string | null ) => { return new Promise(async (resolve, reject) => { @@ -14,7 +13,6 @@ export const uploadDocuments = async ( method: 'POST', body: formData, }, - sessionId, jwtToken, isApplicationJson: false, }); diff --git a/packages/web-ui/api/requests/users/get-all-users.ts b/packages/web-ui/api/requests/users/get-all-users.ts index b849f42..3c6bc02 100644 --- a/packages/web-ui/api/requests/users/get-all-users.ts +++ b/packages/web-ui/api/requests/users/get-all-users.ts @@ -4,15 +4,11 @@ import { UserResponseDto } from '@/contract/auth/user.response.dto.d'; export const GET_ALL_USERS_REQ_KEY = 'all-users'; -export const getAllUsers = async ( - sessionId: string | null, - jwtToken: string | null -) => { +export const getAllUsers = async (jwtToken: string | null) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.users.getUsers(), options: { method: 'GET' }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/users/get-user.ts b/packages/web-ui/api/requests/users/get-user.ts index 0141d70..309cf3f 100644 --- a/packages/web-ui/api/requests/users/get-user.ts +++ b/packages/web-ui/api/requests/users/get-user.ts @@ -6,14 +6,12 @@ export const GET_USER_REQ_KEY = 'user'; export const getUser = async ( userId: string | undefined, - sessionId: string | null, jwtToken: string | null ) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.users.getUser(userId ?? ''), options: { method: 'GET' }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/api/requests/users/get-users.ts b/packages/web-ui/api/requests/users/get-users.ts index 7e14add..7dfffe7 100644 --- a/packages/web-ui/api/requests/users/get-users.ts +++ b/packages/web-ui/api/requests/users/get-users.ts @@ -6,14 +6,12 @@ export const GET_USERS_REQ_KEY = 'users'; export const getUsers = async ( userIds: string[] | undefined, - sessionId: string | null, jwtToken: string | null ) => { return new Promise(async (resolve, reject) => { const res = await apiClient({ url: Endpoints.users.getUsers(userIds ?? []), options: { method: 'GET' }, - sessionId, jwtToken, }); diff --git a/packages/web-ui/app/rooms/[room]/layout.tsx b/packages/web-ui/app/rooms/[room]/layout.tsx index 3d59f0e..36748ef 100644 --- a/packages/web-ui/app/rooms/[room]/layout.tsx +++ b/packages/web-ui/app/rooms/[room]/layout.tsx @@ -21,18 +21,18 @@ export default async function RoomLayout({ children, params, }: RootLayoutProps) { - const { sessionId, getToken } = auth(); + const { getToken } = auth(); const token = await getToken(); const queryClient = getQueryClient(); const room = await queryClient.fetchQuery([GET_ROOM_REQ_KEY], () => - getRoom(params.room, sessionId, token) + getRoom(params.room, token) ); const chat = await queryClient.fetchQuery([GET_CHAT_REQ_KEY], () => - getChat(params.room, sessionId, token) + getChat(params.room, token) ); const aiModel = await queryClient.fetchQuery([GET_AI_MODEL_REQ_KEY], () => - getAiModel(chat.aiModelId ?? '', sessionId, token) + getAiModel(chat.aiModelId ?? '', token) ); const dehydratedState = dehydrate(queryClient); diff --git a/packages/web-ui/app/rooms/[room]/page.tsx b/packages/web-ui/app/rooms/[room]/page.tsx index fdcd30e..3f5bb49 100644 --- a/packages/web-ui/app/rooms/[room]/page.tsx +++ b/packages/web-ui/app/rooms/[room]/page.tsx @@ -9,17 +9,17 @@ import { ChatTools } from '@/components/chat-tools'; import getQueryClient from '@/app/get-query-client'; export default async function Room({ params }: { params: { room: string } }) { - const { sessionId, getToken, userId } = auth(); + const { getToken, userId } = auth(); const token = await getToken(); const queryClient = getQueryClient(); const room = await queryClient.fetchQuery([GET_ROOM_REQ_KEY], () => - getRoom(params.room, sessionId, token) + getRoom(params.room, token) ); const chat = await queryClient.fetchQuery([GET_CHAT_REQ_KEY], () => - getChat(params.room, sessionId, token) + getChat(params.room, token) ); const owner = await queryClient.fetchQuery([GET_USER_REQ_KEY], () => - getUser(room.ownerId, sessionId, token) + getUser(room.ownerId, token) ); const dehydratedState = dehydrate(queryClient); const isOwner = owner.id === userId; diff --git a/packages/web-ui/app/rooms/[room]/settings/page.tsx b/packages/web-ui/app/rooms/[room]/settings/page.tsx index 9a5c379..a4f98a5 100644 --- a/packages/web-ui/app/rooms/[room]/settings/page.tsx +++ b/packages/web-ui/app/rooms/[room]/settings/page.tsx @@ -50,20 +50,20 @@ export default async function Settings({ }: { params: { room: string }; }) { - const { userId, sessionId, getToken } = auth(); + const { userId, getToken } = auth(); const token = await getToken(); const queryClient = getQueryClient(); const room = await queryClient.fetchQuery([GET_ROOM_REQ_KEY], () => - getRoom(params.room, sessionId, token) + getRoom(params.room, token) ); const members = await queryClient.fetchQuery([GET_USERS_REQ_KEY], () => - getUsers(room.members, sessionId, token) + getUsers(room.members, token) ); const allUsers = await queryClient.fetchQuery([GET_ALL_USERS_REQ_KEY], () => - getAllUsers(sessionId, token) + getAllUsers(token) ); const owner = await queryClient.fetchQuery([GET_USER_REQ_KEY], () => - getUser(room.ownerId, sessionId, token) + getUser(room.ownerId, token) ); const dehydratedState = dehydrate(queryClient); diff --git a/packages/web-ui/app/rooms/layout.tsx b/packages/web-ui/app/rooms/layout.tsx index c93af8d..5041286 100644 --- a/packages/web-ui/app/rooms/layout.tsx +++ b/packages/web-ui/app/rooms/layout.tsx @@ -15,11 +15,11 @@ interface RootLayoutProps { } export default async function RoomsLayout({ children }: RootLayoutProps) { - const { sessionId, getToken } = auth(); + const { getToken } = auth(); const token = await getToken(); const queryClient = getQueryClient(); await queryClient.prefetchQuery([GET_MY_ROOMS_REQ_KEY], () => - getMyRooms(sessionId, token) + getMyRooms(token) ); const dehydratedState = dehydrate(queryClient); diff --git a/packages/web-ui/app/rooms/page.tsx b/packages/web-ui/app/rooms/page.tsx index 9ec07a2..3d1eda8 100644 --- a/packages/web-ui/app/rooms/page.tsx +++ b/packages/web-ui/app/rooms/page.tsx @@ -26,12 +26,12 @@ const getSearchRoomsList = ( }; export default async function Rooms() { - const { sessionId, getToken, userId } = auth(); + const { getToken, userId } = auth(); const token = await getToken(); const queryClient = getQueryClient(); const publicRooms = await queryClient.fetchQuery( [GET_PUBLIC_ROOMS_REQ_KEY], - () => getPublicRooms(sessionId, token) + () => getPublicRooms(token) ); const dehydratedState = dehydrate(queryClient); const publicRoomsSearchList = getSearchRoomsList(publicRooms, userId); diff --git a/packages/web-ui/components/chat-tools.tsx b/packages/web-ui/components/chat-tools.tsx index a402f95..696ff34 100644 --- a/packages/web-ui/components/chat-tools.tsx +++ b/packages/web-ui/components/chat-tools.tsx @@ -41,11 +41,11 @@ type ChatToolsProps = { }; export function ChatTools({ documents, roomId, isOwner }: ChatToolsProps) { - const { sessionId, getToken } = useAuth(); + const { getToken } = useAuth(); const router = useRouter(); const { mutate: deleteDocumentMutationReq, isLoading } = useMutation({ mutationFn: async (values: RemoveDocumentFromChatRequestDto) => - deleteDocument(roomId, values, sessionId!, await getToken()), + deleteDocument(roomId, values, await getToken()), onError: (error: any) => { toast({ title: error, diff --git a/packages/web-ui/components/chat.tsx b/packages/web-ui/components/chat.tsx index 8ba676b..b4a2ed1 100644 --- a/packages/web-ui/components/chat.tsx +++ b/packages/web-ui/components/chat.tsx @@ -55,11 +55,11 @@ export default function Chat({ hasDocuments, ownerRoles, }: ChatProps) { - const { sessionId, userId, getToken } = useAuth(); + const { userId, getToken } = useAuth(); const queryClient = useQueryClient(); const { data: chat } = useQuery({ queryKey: [GET_CHAT_REQ_KEY], - queryFn: async () => getChat(roomId, sessionId!, await getToken()), + queryFn: async () => getChat(roomId, await getToken()), }); const [messages, setMessages] = useState([]); const [participants, setParticipants] = useRefState([]); @@ -89,7 +89,7 @@ export default function Chat({ const user = await queryClient.fetchQuery({ queryKey: [GET_USER_REQ_KEY], - queryFn: async () => getUser(userId, sessionId!, await getToken()), + queryFn: async () => getUser(userId, await getToken()), }); if (!user) { @@ -124,7 +124,7 @@ export default function Chat({ if (chat && chat.participantIds.length > 0) { const participantList = createChatParticipantsFactory( await queryClient.fetchQuery([GET_USERS_REQ_KEY], async () => - getUsers(chat.participantIds, sessionId!, await getToken()) + getUsers(chat.participantIds, await getToken()) ) ); diff --git a/packages/web-ui/components/create-room-form.tsx b/packages/web-ui/components/create-room-form.tsx index 597b1b5..1da44a6 100644 --- a/packages/web-ui/components/create-room-form.tsx +++ b/packages/web-ui/components/create-room-form.tsx @@ -46,11 +46,11 @@ type CreateRoomFormProps = { export function CreateRoomForm({ aiModels }: CreateRoomFormProps) { const [open, setOpen] = useState(false); const { toast } = useToast(); - const { userId, sessionId, getToken } = useAuth(); + const { userId, getToken } = useAuth(); const router = useRouter(); const { mutate: createRoomMutationReq, isLoading } = useMutation({ mutationFn: async (values: CreateRoomRequestDto) => - createRoom(values, sessionId!, await getToken()), + createRoom(values, await getToken()), onError: (error: any) => { toast({ title: error, diff --git a/packages/web-ui/components/delete-room.tsx b/packages/web-ui/components/delete-room.tsx index 7329830..f3285ec 100644 --- a/packages/web-ui/components/delete-room.tsx +++ b/packages/web-ui/components/delete-room.tsx @@ -14,9 +14,9 @@ import { Popover, PopoverContent, PopoverTrigger } from './ui/popover'; export default function DeleteRoom({ roomId }: { roomId: string }) { const router = useRouter(); const { toast } = useToast(); - const { sessionId, getToken } = useAuth(); + const { getToken } = useAuth(); const { mutate: deleteRoomMutationReq, isLoading } = useMutation({ - mutationFn: async () => deleteRoom(roomId, sessionId!, await getToken()), + mutationFn: async () => deleteRoom(roomId, await getToken()), onError: (error: any) => { toast({ title: error, diff --git a/packages/web-ui/components/document-upload-form.tsx b/packages/web-ui/components/document-upload-form.tsx index 3fa2c73..0a1a3ec 100644 --- a/packages/web-ui/components/document-upload-form.tsx +++ b/packages/web-ui/components/document-upload-form.tsx @@ -46,7 +46,7 @@ export function DocumentUploadForm({ ownerRoles }: DocumentUploadFormProps) { const { room: roomId } = useParams(); const [open, setOpen] = useState(false); const { toast } = useToast(); - const { sessionId, getToken } = useAuth(); + const { getToken } = useAuth(); const router = useRouter(); const { isMacUser } = useBrowserInfo(); const { mutate: uploadDocumentsMutationReq, isLoading } = useMutation({ @@ -56,7 +56,7 @@ export function DocumentUploadForm({ ownerRoles }: DocumentUploadFormProps) { }: { roomId: string; formData: FormData; - }) => uploadDocuments(roomId, formData, sessionId!, await getToken()), + }) => uploadDocuments(roomId, formData, await getToken()), onError: (error: any) => { toast({ title: error, diff --git a/packages/web-ui/components/leave-room.tsx b/packages/web-ui/components/leave-room.tsx index d2f7ea3..72d8a57 100644 --- a/packages/web-ui/components/leave-room.tsx +++ b/packages/web-ui/components/leave-room.tsx @@ -15,10 +15,10 @@ import { Popover, PopoverContent, PopoverTrigger } from './ui/popover'; export default function LeaveRoom({ roomId }: { roomId: string }) { const router = useRouter(); const { toast } = useToast(); - const { sessionId, getToken } = useAuth(); + const { getToken } = useAuth(); const { mutate: leaveRoomMutationReq, isLoading } = useMutation({ mutationFn: async (values: LeaveRoomRequestDto) => - leaveRoom(values, sessionId!, await getToken()), + leaveRoom(values, await getToken()), onError: (error: any) => { toast({ title: error, diff --git a/packages/web-ui/components/room-search-items.tsx b/packages/web-ui/components/room-search-items.tsx index bda04cd..33f3d9d 100644 --- a/packages/web-ui/components/room-search-items.tsx +++ b/packages/web-ui/components/room-search-items.tsx @@ -19,11 +19,11 @@ export default function RoomSearchItems({ data: PublicRoomsListType[]; }) { const { toast } = useToast(); - const { sessionId, getToken } = useAuth(); + const { getToken } = useAuth(); const router = useRouter(); const { mutate: joinRoomMutationReq, isLoading } = useMutation({ mutationFn: async (values: JoinRoomRequestDto) => - joinRoom(values, sessionId!, await getToken()), + joinRoom(values, await getToken()), onError: (error: any) => { toast({ title: error, diff --git a/packages/web-ui/components/rooms.tsx b/packages/web-ui/components/rooms.tsx index e4bad28..04103ba 100644 --- a/packages/web-ui/components/rooms.tsx +++ b/packages/web-ui/components/rooms.tsx @@ -26,14 +26,14 @@ import { CreateRoomForm } from '@/components/create-room-form'; export function Rooms() { const params = useParams(); - const { sessionId, getToken } = useAuth(); + const { getToken } = useAuth(); const { data: myRooms } = useQuery({ queryKey: [GET_MY_ROOMS_REQ_KEY], - queryFn: async () => getMyRooms(sessionId!, await getToken()), + queryFn: async () => getMyRooms(await getToken()), }); const { data: aiModels } = useQuery({ queryKey: [GET_AI_MODELS_REQ_KEY], - queryFn: async () => getAiModels(sessionId!, await getToken()), + queryFn: async () => getAiModels(await getToken()), }); return ( diff --git a/packages/web-ui/components/site-header.tsx b/packages/web-ui/components/site-header.tsx index 2481bc3..a5a6ec3 100644 --- a/packages/web-ui/components/site-header.tsx +++ b/packages/web-ui/components/site-header.tsx @@ -42,7 +42,7 @@ export function SiteHeader() { const router = useRouter(); const pathname = usePathname(); const { isSignedIn } = useUser(); - const { sessionId, getToken, userId } = useAuth(); + const { getToken, userId } = useAuth(); const { isMacUser } = useBrowserInfo(); const shouldShowSearchRoomsShortCut = useMemo( () => isSignedIn && !pathname.includes('admin'), @@ -50,15 +50,15 @@ export function SiteHeader() { ); const { data: myRooms } = useQuery({ queryKey: [GET_MY_ROOMS_REQ_KEY], - queryFn: async () => getMyRooms(sessionId!, await getToken()), + queryFn: async () => getMyRooms(await getToken()), }); const { data: publicRooms } = useQuery({ queryKey: [GET_PUBLIC_ROOMS_REQ_KEY], - queryFn: async () => getPublicRooms(sessionId!, await getToken()), + queryFn: async () => getPublicRooms(await getToken()), }); const { mutate: joinRoomMutationReq, isLoading } = useMutation({ mutationFn: async (values: JoinRoomRequestDto) => - joinRoom(values, sessionId!, await getToken()), + joinRoom(values, await getToken()), onError: (error: any) => { toast({ title: error, diff --git a/packages/web-ui/components/update-room-form.tsx b/packages/web-ui/components/update-room-form.tsx index ba07324..6a8cc0e 100644 --- a/packages/web-ui/components/update-room-form.tsx +++ b/packages/web-ui/components/update-room-form.tsx @@ -30,10 +30,10 @@ interface UpdateRoomFormProps { export function UpdateRoomForm({ room }: UpdateRoomFormProps) { const router = useRouter(); const { toast } = useToast(); - const { sessionId, getToken } = useAuth(); + const { getToken } = useAuth(); const { mutate: updateRoomMutationReq, isLoading } = useMutation({ mutationFn: async (values: UpdateRoomSettingsRequestDto) => - updateRoom(room.id, values, sessionId!, await getToken()), + updateRoom(room.id, values, await getToken()), onError: (error: any) => { toast({ title: error, diff --git a/packages/web-ui/components/user-search-items.tsx b/packages/web-ui/components/user-search-items.tsx index d2358ae..3d9e5cf 100644 --- a/packages/web-ui/components/user-search-items.tsx +++ b/packages/web-ui/components/user-search-items.tsx @@ -36,11 +36,11 @@ export default function UserSearchItems({ isPrivateRoom, }: UserSearchItemsProps) { const { toast } = useToast(); - const { sessionId, getToken } = useAuth(); + const { getToken } = useAuth(); const router = useRouter(); const { mutate: inviteUserToRoomMutationReq, isLoading } = useMutation({ mutationFn: async (values: InviteUserToRoomRequestDto) => - inviteUserToRoom(values, sessionId!, await getToken()), + inviteUserToRoom(values, await getToken()), onError: (error: any) => { toast({ title: error,