u
This commit is contained in:
28
src/store/companyuser/roles.js
Normal file
28
src/store/companyuser/roles.js
Normal file
@@ -0,0 +1,28 @@
|
||||
export const COMPANY_USER_ROLES = ['admin', 'user'];
|
||||
|
||||
/**
|
||||
* Validates a company user role.
|
||||
* @param {unknown} role
|
||||
* @returns {'admin'|'user'}
|
||||
* @throws {Error} 'Invalid role'
|
||||
*/
|
||||
export function assertRole(role) {
|
||||
if (!COMPANY_USER_ROLES.includes(role)) {
|
||||
throw new Error('Invalid role');
|
||||
}
|
||||
return role;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes and validates an email address.
|
||||
* @param {unknown} email
|
||||
* @returns {string} lower-cased, trimmed email
|
||||
* @throws {Error} 'Invalid email'
|
||||
*/
|
||||
export function normalizeEmail(email) {
|
||||
const value = typeof email === 'string' ? email.trim().toLowerCase() : '';
|
||||
if (!value || !value.includes('@')) {
|
||||
throw new Error('Invalid email');
|
||||
}
|
||||
return value;
|
||||
}
|
||||
Reference in New Issue
Block a user