-
Notifications
You must be signed in to change notification settings - Fork 1
Critical Authentication Hot fixes (Urgent) #149
Conversation
…an optimized production build
…robust for all account uses cases from Clerk
@@ -88,7 +88,7 @@ export function FriendsTab(props: TextInputProps) { | |||
|
|||
if (activeChat && user?.id) { // Ensure both activeChat and user.id are defined | |||
return <Chat | |||
sender={user.id} | |||
sender={user.username as any} |
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.
Great change to using username so that it fits with our current database field name
@@ -8,12 +8,19 @@ export default authMiddleware({ | |||
publicRoutes: [ | |||
'/', | |||
'/api/webhooks/clerk-mongodb-sync', | |||
'/api/registration', | |||
'/api/update-user-data', | |||
'/api/ably-auth', |
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.
Good inclusion of the path to all the APIs that are integrated so far.
@@ -2,7 +2,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; | |||
import Ably from 'ably/promises'; | |||
|
|||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | |||
if (req.method === 'GET') { | |||
if (req.method === 'POST') { |
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.
- Ensure robust error handling, especially around asynchronous operations like network requests. While you have a try-catch block to handle errors from Ably, consider adding specific error handling for different types of errors to provide more informative responses to clients.
@@ -5,7 +5,7 @@ import { getMongoDbUri } from '@/lib/dbConfig'; | |||
|
|||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | |||
if (req.method === 'POST') { | |||
const { id } = JSON.parse(req.body); // Assuming the email is sent in the body | |||
const { id } = req.body; // Directly destructuring `id` from `req.body` because it's already an object |
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.
- Great code refactoring to reduce redundancy.
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.
object Object
|
||
try { | ||
client = new MongoClient(getMongoDbUri()); | ||
await client.connect(); | ||
const db = client.db('Accord'); | ||
|
||
const accountsCollection = db.collection("Accounts"); | ||
// Querying the database by the userName we received | ||
|
||
// First, check if an account with the same 'id' or 'userName' already exists |
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.
- Great change to ensure that there is no duplication in username and ensuring that an account for that particular id has not been created before.
} catch (error) { | ||
console.error(error); | ||
console.error('Failed to register user:', error); |
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.
- Enhance error handling to provide more informative error messages to clients and aid in troubleshooting. Instead of a generic "Internal server error" message, consider providing more context about the specific error that occurred.
}); | ||
|
||
if (!response.ok) { |
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.
- Enhance error handling to provide more informative error messages and to handle different error scenarios appropriately. For example, in the user.deleted case, ensure that errors from the API call are properly handled, and consider providing more context about the nature of the error.
@@ -1,3 +1,3 @@ | |||
export function MyAccount() { | |||
export default function MyAccount() { |
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.
- This can be good code-refactoring. However, if we need to export multiple items or want to be more explicit about what you're exporting in the future, we can use named exports (without the default) instead.
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.
react complain if not default. i make default. react happy. i happy.
Summary of Changes
clerk-mongodb-sync.ts
now checks if the account already exists in our database)delete-user.ts
)npm run accord
command inpackage.json
was launching the wrongngrok
server (the randomly generated one instead of the static domain, hence we were effectively creating 2 servers each time if you would run thengrok
command for the static server I created before doingnpm run accord
).