@@ -140,9 +140,7 @@ const editAccount = async (req, res) => {
140140
141141 const session = req . cookies . session // Get session from browser cookies
142142
143- const id = await getIdFromSession ( session ) // Get user ID from session
144-
145- const { username : oldUsername , password : oldHash } = await getUserDetails ( id ) // Get current details about user from database
143+ const { id, username : oldUsername , password : oldHash } = await getUserDetails ( session ) // Get current details about user from database
146144
147145 // Check if password given as verification is correct
148146 const verifyPasswordCorrect = await bcrypt . compare ( verifyPassword , oldHash )
@@ -157,7 +155,7 @@ const editAccount = async (req, res) => {
157155 const password = req . body . password /// Get plaintext password
158156
159157 // Check if new username is not already taken by another account
160- const usernameTaken = await accDb . get ( "SELECT * FROM users WHERE username = ?" , username )
158+ const usernameTaken = await db . get ( "SELECT * FROM users WHERE username = ?" , username )
161159
162160 if ( usernameTaken && oldUsername !== username ) { // Username is already in use and it's not the user's current username
163161 res . status ( 409 ) . end ( "Username already in use." )
@@ -189,9 +187,7 @@ const deleteAccount = async (req, res) => {
189187
190188 const session = req . cookies . session // Get session from cookie
191189
192- const id = await getIdFromSession ( session ) // Get ID from session
193-
194- const { password : hash } = await getUserDetails ( id ) // Get account password as bcrypt hash
190+ const { id, password : hash } = await getUserDetails ( session ) // Get account password as bcrypt hash
195191
196192 // Check that password for verification is correct
197193 const verifyPasswordCorrect = await bcrypt . compare ( verifyPassword , hash )
0 commit comments