mirror of
				https://github.com/xfarrow/blink
				synced 2025-06-27 09:03:02 +02:00 
			
		
		
		
	update
This commit is contained in:
		| @@ -99,7 +99,7 @@ app.post('/api/register', (req, res) => { | |||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| app.post('/api/registerv2', (req, res) => { | app.post('/api/registerv2', async (req, res) => { | ||||||
|   const userData = req.body; |   const userData = req.body; | ||||||
|    |    | ||||||
|   // Ensure that the required fields are present before proceeding |   // Ensure that the required fields are present before proceeding | ||||||
| @@ -107,47 +107,36 @@ app.post('/api/registerv2', (req, res) => { | |||||||
|     return res.status(400).json("Invalid request"); |     return res.status(400).json("Invalid request"); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   bcrypt.hash(userData.password, 10) |   const hashPasswordPromise = bcrypt.hash(userData.password, 10); | ||||||
|     .then( hashedPassword => { |   var client; | ||||||
|       // Generate activation link token |   try{ | ||||||
|       const activationLink = crypto.randomBytes(16).toString('hex'); |     client = await pool.connect(); | ||||||
|           // Acquire a connection from the pool |  | ||||||
|           pool.connect() |  | ||||||
|           .then(async (client) => { |  | ||||||
|             // SQL query with placeholders for parameters |  | ||||||
|     const insertQuery = ` |     const insertQuery = ` | ||||||
|       INSERT INTO "User" (display_name, date_of_birth, place_of_living, is_looking_for_job, email, password) |       INSERT INTO "User" (display_name, date_of_birth, place_of_living, is_looking_for_job, email, password) | ||||||
|       VALUES ($1, $2, $3, $4, $5, $6) |       VALUES ($1, $2, $3, $4, $5, $6) | ||||||
|             RETURNING *`; // Return the inserted row |       RETURNING *`; | ||||||
|        |  | ||||||
|           try { |  | ||||||
|               try { |  | ||||||
|     const result = await client.query(insertQuery, [ |     const result = await client.query(insertQuery, [ | ||||||
|       userData.display_name, |       userData.display_name, | ||||||
|       userData.date_of_birth, |       userData.date_of_birth, | ||||||
|       userData.place_of_living, |       userData.place_of_living, | ||||||
|       userData.is_looking_for_job, |       userData.is_looking_for_job, | ||||||
|       userData.email, |       userData.email, | ||||||
|                   hashedPassword |       await hashPasswordPromise | ||||||
|     ]); |     ]); | ||||||
|                 // Respond with the inserted user data |  | ||||||
|     res.status(200).json(result.rows[0]); |     res.status(200).json(result.rows[0]); | ||||||
|               } catch (error) { |   } | ||||||
|  |   catch (error){ | ||||||
|     console.error('Error inserting data:', error); |     console.error('Error inserting data:', error); | ||||||
|     res.status(500).json("Internal server error"); |     res.status(500).json("Internal server error"); | ||||||
|   } |   } | ||||||
|             } finally { |   finally { | ||||||
|               // Release the connection back to the pool |     if (client) { | ||||||
|       client.release(); |       client.release(); | ||||||
|     } |     } | ||||||
|         }) |   } | ||||||
|         .catch((error) => { |  | ||||||
|           console.error('Error acquiring a connection from the pool:', error); |  | ||||||
|           res.status(500).json("Internal server error"); |  | ||||||
|         }); |  | ||||||
|     }); |  | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  |  | ||||||
| // Start the server | // Start the server | ||||||
| app.listen(port, () => { | app.listen(port, () => { | ||||||
|   console.log(`Blink API server is running on port ${port}`); |   console.log(`Blink API server is running on port ${port}`); | ||||||
|   | |||||||
| @@ -29,3 +29,4 @@ ASYNCHRONOUS | |||||||
|          |--------B--------| |          |--------B--------| | ||||||
|  |  | ||||||
| Where Process A overlaps Process B, they're running concurrently or synchronously (dictionary definition), hence the confusion.  | Where Process A overlaps Process B, they're running concurrently or synchronously (dictionary definition), hence the confusion.  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user