Overhaul settings and implement user preferences. Also implements dark theme toggle as part of the user settings.
This commit is contained in:
parent
b84f0907a8
commit
727746030c
17 changed files with 760 additions and 378 deletions
|
@ -48,7 +48,8 @@ async function getAuthenticatorByCredentialID(credentialID)
|
|||
// Generate Registration Options
|
||||
router.post('/generate-registration-options', async(req, res) =>
|
||||
{
|
||||
const { username } = req.body;
|
||||
// Destructure username, email, and fullName from the request body
|
||||
const { username, email, fullName } = req.body;
|
||||
|
||||
if (!username)
|
||||
{
|
||||
|
@ -59,13 +60,18 @@ router.post('/generate-registration-options', async(req, res) =>
|
|||
{
|
||||
let user = await getUserByUsername(username);
|
||||
|
||||
// If user doesn't exist, create one
|
||||
// If user doesn't exist, create one with the provided details
|
||||
if (!user)
|
||||
{
|
||||
const userData = { username };
|
||||
if (email) userData.email = email; // Add email if provided
|
||||
if (fullName) userData.fullName = fullName; // Add fullName if provided
|
||||
|
||||
user = await prisma.user.create({
|
||||
data: { username },
|
||||
data: userData,
|
||||
});
|
||||
}
|
||||
// ... rest of the existing logic ...
|
||||
|
||||
const userAuthenticators = await getUserAuthenticators(user.id);
|
||||
|
||||
|
@ -107,6 +113,11 @@ router.post('/generate-registration-options', async(req, res) =>
|
|||
catch (error)
|
||||
{
|
||||
console.error('Registration options error:', error);
|
||||
// Handle potential Prisma unique constraint errors (e.g., email already exists)
|
||||
if (error.code === 'P2002' && error.meta?.target?.includes('email'))
|
||||
{
|
||||
return res.status(409).json({ error: 'Email address is already in use.' });
|
||||
}
|
||||
res.status(500).json({ error: 'Failed to generate registration options' });
|
||||
}
|
||||
});
|
||||
|
@ -190,12 +201,18 @@ router.post('/verify-registration', async(req, res) =>
|
|||
}
|
||||
else
|
||||
{
|
||||
// This else block was previously misplaced before the if block
|
||||
res.status(400).json({ error: 'Registration verification failed' });
|
||||
}
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
console.error('Registration verification error:', error);
|
||||
// Handle potential Prisma unique constraint errors (e.g., email already exists)
|
||||
if (error.code === 'P2002' && error.meta?.target?.includes('email'))
|
||||
{
|
||||
return res.status(409).json({ error: 'Email address is already in use.' });
|
||||
}
|
||||
challengeStore.delete(userId); // Clean up challenge on error
|
||||
delete req.session.userId;
|
||||
res.status(500).json({ error: 'Failed to verify registration', details: error.message });
|
||||
|
@ -437,7 +454,8 @@ router.get('/status', async(req, res) =>
|
|||
{});
|
||||
return res.status(401).json({ status: 'unauthenticated' });
|
||||
}
|
||||
return res.json({ status: 'authenticated', user: { id: user.id, username: user.username, email: user.email } });
|
||||
// Include email and fullName in the response
|
||||
return res.json({ status: 'authenticated', user: { id: user.id, username: user.username, email: user.email, fullName: user.fullName } });
|
||||
}
|
||||
res.json({ status: 'unauthenticated' });
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue