MCPcopy
hub / github.com/stephengpope/thepopebot / addUser

Function addUser

lib/auth/actions.js:53–75  ·  view source on GitHub ↗
(email, password, role)

Source from the content-addressed store, hash-verified

51 * Add a new user.
52 */
53export async function addUser(email, password, role) {
54 await requireAdmin();
55
56 if (!email || !password) {
57 return { error: 'Email and password are required.' };
58 }
59 if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
60 return { error: 'Invalid email format.' };
61 }
62 if (password.length < 8) {
63 return { error: 'Password must be at least 8 characters.' };
64 }
65
66 try {
67 await createUser(email, password, role || 'user');
68 return { success: true };
69 } catch (err) {
70 if (err.message?.includes('UNIQUE constraint')) {
71 return { error: 'A user with this email already exists.' };
72 }
73 return { error: 'Failed to create user.' };
74 }
75}
76
77/**
78 * Edit a user's email and/or role.

Callers 1

handleCreateFunction · 0.90

Calls 2

requireAdminFunction · 0.90
createUserFunction · 0.90

Tested by

no test coverage detected