WayrApp Backend & Ecosystem Documentation - v1.0.0
    Preparing search index...

    Variable RoleSchemaConst

    RoleSchema: ZodEnum<["student", "content_creator", "admin"]> = ...

    User role validation schema for authorization and access control

    Enumeration schema that defines and validates the three primary user roles in the WayrApp language learning platform. This schema ensures consistent role-based access control throughout the application and prevents invalid role assignments that could compromise security or functionality.

    The three roles provide a hierarchical permission structure: students have basic learning access, content creators can manage educational content, and administrators have full system access. This role system supports the platform's educational workflow while maintaining security boundaries.

    // User role assignment validation
    const UserRoleUpdateSchema = z.object({
    userId: z.string().uuid(),
    newRole: RoleSchema,
    reason: z.string().optional()
    });
    // Role-based content filtering
    const ContentAccessSchema = z.object({
    userRole: RoleSchema,
    contentType: z.string(),
    requestedAccess: z.enum(['read', 'write', 'delete'])
    });
    // Authorization middleware integration
    const requireRole = (allowedRoles: z.infer<typeof RoleSchema>[]) => {
    return (req: Request, res: Response, next: NextFunction) => {
    const userRole = RoleSchema.parse(req.user.role);
    if (allowedRoles.includes(userRole)) {
    next();
    } else {
    res.status(403).json({ error: 'Insufficient permissions' });
    }
    };
    };