Authentication and Authorization
Relevant source files
The following files were used as context for generating this wiki page:
- apps/web/app/api/auth/signin-workspace/signin-workspace.ts
- apps/web/core/hooks/auth/use-authentication-password.ts
- apps/web/core/constants/config/constants.tsx
- apps/web/core/services/client/api.service.ts
- docker-compose.build.yml
- apps/mobile/app/services/hooks/features/use-authentication-team.ts
- README.md
- apps/web/core/types/schemas/README.md
The Ever Teams platform implements a comprehensive authentication and authorization system that relies on its backend, the Ever Gauzy Platform. The system supports multiple authentication methods, including email/password, invitation codes, and various OAuth providers. Once authenticated, user access is governed by a role-based authorization model.
Session management is handled through a set of HTTP cookies containing tokens and user context, while API requests are secured using Bearer token authentication. The frontend architecture includes dedicated hooks for managing authentication state and services that automatically attach credentials to outgoing requests.
Authentication Flows
The platform supports several distinct flows for user authentication and onboarding.
Password-Based Authentication
This is a multi-step process for users who already have an account. It involves validating credentials and then selecting a workspace to sign into. The useAuthenticationPassword hook orchestrates this flow on the client side.
The diagram below illustrates the sequence for password-based login.
Invitation Code Flow
New users can be onboarded via an invitation code sent to their email. This flow allows them to join a team without pre-registering a password. The system verifies the code, creates a user account with a randomly generated password, and logs them in.
This process is handled by the /api/auth/signin-workspace endpoint.
The diagram below shows the flow for signing in with an invitation code.
Session Management & API Authentication
Upon successful authentication, the server sets several HTTP cookies to manage the user's session and context. These cookies are essential for subsequent API requests and maintaining the application state.
The APIService class includes a request interceptor that automatically attaches the Authorization header with a Bearer token to every outgoing API call.
// apps/web/core/services/client/api.service.ts:153-165
private setupRequestInterceptors(): void {
this.axiosInstance.interceptors.request.use(
async (config: any) => {
const tenantId = getTenantIdCookie();
const cookie = getAccessTokenCookie();
if (cookie) {
config.headers['Authorization'] = `Bearer ${cookie}`;
}
if (tenantId) {
config.headers['tenant-id'] = tenantId;
}
// ...
Sources: apps/web/core/services/client/api.service.ts:153-165
Key Authentication Cookies
The following cookies are set after a successful login to manage the session:
| Cookie Name | Purpose |
|---|---|
auth-token | The primary JWT access token for API authentication. |
auth-refresh-token | The refresh token used to obtain a new access token. |
auth-active-team | Stores the ID of the currently selected team. |
auth-user-id | The ID of the authenticated user. |
auth-tenant-id | The ID of the tenant the user is operating within. |
auth-organization-id | The ID of the user's current organization. |
Sources: apps/web/core/constants/config/constants.tsx:120-129, apps/web/app/api/auth/signin-workspace/signin-workspace.ts:133-149
Authorization
Authorization in Ever Teams is managed through a system of roles and permissions, ensuring that users can only access features and data appropriate for their level of access.
Roles
The system defines a set of predefined roles, some of which are system-level and others are user-configurable.
| Role Name | System Role |
|---|---|
SUPER_ADMIN | Yes |
ADMIN | Yes |
MANAGER | No |
EMPLOYEE | Yes |
DATA_ENTRY | No |
VIEWER | Yes |
CANDIDATE | Yes |
INTERVIEWER | No |
Sources: apps/web/core/constants/config/constants.tsx:29-87
Permissions
Permissions are defined through a PERMISSION_ROLES map, which specifies which roles can manage other roles. This creates a hierarchical structure for user management.
The diagram below illustrates the management hierarchy defined by PERMISSION_ROLES.
Protected Routes
The application protects certain URL paths, redirecting unauthenticated users to a login page. This is configured via a list of regular expressions.
Key protected paths include:
/(Dashboard)/profile/*/settings/*/task/*
Sources: apps/web/core/constants/config/constants.tsx:112-119
Configuration
Authentication and authorization behavior is configured primarily through environment variables, which are passed to the application container.
Environment Variables
The following table lists key environment variables related to authentication.
| Variable | Description | Example Value |
|---|---|---|
AUTH_SECRET | A secret key used by NextAuth.js for signing tokens. | my-super-secret-key |
GAUZY_API_SERVER_URL | The base URL of the Ever Gauzy backend API. | https://api.ever.team |
GOOGLE_CLIENT_ID | Client ID for Google OAuth. | ...apps.googleusercontent.com |
GOOGLE_CLIENT_SECRET | Client secret for Google OAuth. | GOCSPX-... |
GITHUB_CLIENT_ID | Client ID for GitHub OAuth. | Iv1... |
GITHUB_CLIENT_SECRET | Client secret for GitHub OAuth. | ... |
INVITE_CALLBACK_URL | The full URL for the invitation acceptance callback. | https://app.ever.team/auth/accept-invite |
VERIFY_EMAIL_CALLBACK_URL | The full URL for the email verification callback. | https://app.ever.team/verify-email |
Sources: docker-compose.build.yml, apps/web/core/constants/config/constants.tsx:550-580
Summary
The authentication and authorization system in Ever Teams is robust and flexible, catering to different user onboarding scenarios while ensuring secure access to the platform's features. It leverages the power of the Ever Gauzy backend for core logic, with the Next.js frontend handling state management, routing, and API communication. The role-based permission model provides granular control over user capabilities, making it suitable for teams and organizations of various sizes.