Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Critical Authentication Hot fixes (Urgent) #149

Merged
merged 4 commits into from
Mar 26, 2024
Merged

Conversation

ColinLefter
Copy link
Owner

Summary of Changes

  • Delivered critical hotfixes that would otherwise cause a chained series of critical issues to our application development (like duplicate MongoDB accounts, inability to delete accounts, etc.)
  • Patched duplicate account creation in MongoDB due to Clerk sending multiple "Account created" alerts to our webhook endpoint (clerk-mongodb-sync.ts now checks if the account already exists in our database)
  • Patched non-functional account deletion endpoint (delete-user.ts)
  • Fixed non-functional direct messaging
  • Fixed direct messaging using the internal id instead of the username
  • Patched a critical issue where the npm run accord command in package.json was launching the wrong ngrok server (the randomly generated one instead of the static domain, hence we were effectively creating 2 servers each time if you would run the ngrok command for the static server I created before doing npm run accord).

@ColinLefter ColinLefter requested a review from Hocng7 March 25, 2024 23:08
@ColinLefter ColinLefter self-assigned this Mar 25, 2024
@ColinLefter ColinLefter changed the title Authentication hotfixes Critical Authentication Hot fixes (Urgent) Mar 25, 2024
@@ -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}
Copy link
Collaborator

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',
Copy link
Collaborator

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') {
Copy link
Collaborator

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
Copy link
Collaborator

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.

Copy link
Owner Author

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
Copy link
Collaborator

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);
Copy link
Collaborator

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) {
Copy link
Collaborator

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() {
Copy link
Collaborator

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.

Copy link
Owner Author

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.

@Hocng7 Hocng7 merged commit 0dea17f into main Mar 26, 2024
@Hocng7 Hocng7 deleted the authentication-hotfixes branch March 26, 2024 03:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Patch broken delete-user backend API endpoint Patch non-functional text channels due to user ID issue
2 participants