Implement Role Management Features and UI Enhancements
- Introduced a new composable `useActiveRole` for managing user roles, including fetching role status and switching roles with server validation. - Updated `RoleSwitcher.vue` to utilize the new composable, enhancing role selection with improved error handling and UI feedback. - Added new API endpoints for role management, including fetching user role status and switching active roles. - Enhanced product visibility logic to filter based on the user's active role, ensuring a tailored experience. - Updated database schema to support last active role tracking for users, improving session management. - Refined UI components across the application to reflect role-based changes and improve user experience.
This commit is contained in:
@@ -86,7 +86,16 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 6. Create encrypted session
|
||||
// 6. Determine initial active role
|
||||
const approvedRoles = await getUserApprovedRoleCodes(user.id)
|
||||
|
||||
// Use last active role if user had one and still has that role
|
||||
const initialRole =
|
||||
user.lastActiveRoleCode && approvedRoles.includes(user.lastActiveRoleCode)
|
||||
? user.lastActiveRoleCode
|
||||
: approvedRoles[0] || 'private'
|
||||
|
||||
// 7. Create encrypted session
|
||||
await setUserSession(event, {
|
||||
user: {
|
||||
id: user.id,
|
||||
@@ -103,9 +112,14 @@ export default defineEventHandler(async (event) => {
|
||||
},
|
||||
accessToken: tokens.access_token, // Store for logout
|
||||
loggedInAt: new Date().toISOString(),
|
||||
// Role state management
|
||||
activeRoleCode: initialRole,
|
||||
userApprovedRoles: approvedRoles,
|
||||
rolesLastValidated: new Date().toISOString(),
|
||||
roleChangedByAdmin: false,
|
||||
})
|
||||
|
||||
// 7. Return success
|
||||
// 8. Return success
|
||||
return {
|
||||
success: true,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user