agent_crew
agent_crew copied to clipboard
feat: Auth TypeScript types + API client for auth endpoints
Summary
Add TypeScript types for auth entities (User, Organization, Invite) and extend the API client with all auth-related endpoints.
Context
The frontend needs types and API methods to interact with the new auth system. This is the foundation for all auth UI components.
Types (src/types/index.ts)
export interface Organization {
id: string;
name: string;
slug: string;
created_at: string;
updated_at: string;
}
export interface User {
id: string;
org_id: string;
email: string;
name: string;
is_owner: boolean;
created_at: string;
updated_at: string;
}
export interface Invite {
id: string;
token?: string; // Only present on creation response
invite_url?: string; // Only present on creation response
email: string | null;
expires_at: string;
used_at: string | null;
created_at: string;
}
export interface AuthConfig {
provider: 'noop' | 'local' | 'oidc' | 'auth0';
registration_enabled: boolean;
multi_tenant: boolean;
}
export interface AuthTokens {
access_token: string;
refresh_token: string;
expires_in: number;
}
export interface LoginRequest {
email: string;
password: string;
}
export interface RegisterRequest {
org_name: string;
name: string;
email: string;
password: string;
}
export interface InviteRegisterRequest {
token: string;
name: string;
email: string;
password: string;
}
API Client (src/services/api.ts)
authApi module
export const authApi = {
config: () => GET('/api/auth/config'), // AuthConfig
login: (data) => POST('/api/auth/login', data), // AuthTokens + User
register: (data) => POST('/api/auth/register', data), // AuthTokens + User + Org
refresh: (token) => POST('/api/auth/refresh', { refresh_token: token }),
me: () => GET('/api/auth/me'), // User + Organization
inviteInfo: (token) => GET(`/api/auth/invite/${token}`), // Org preview
registerWithInvite: (data) => POST('/api/auth/register/invite', data),
};
orgApi module
export const orgApi = {
get: () => GET('/api/org'),
update: (data) => PUT('/api/org', data),
members: () => GET('/api/org/members'),
removeMember: (id) => DELETE(`/api/org/members/${id}`),
invites: () => GET('/api/org/invites'),
createInvite: (data) => POST('/api/org/invites', data),
deleteInvite: (id) => DELETE(`/api/org/invites/${id}`),
};
Authorization Header
Update the base request() function to:
- Read access token from localStorage (or cookie)
- Add
Authorization: Bearer <token>header to all requests - On 401 response: attempt token refresh, retry once, then redirect to
/login
Token Storage Utility (src/services/auth.ts)
export const auth = {
getAccessToken: () => string | null,
setTokens: (tokens: AuthTokens) => void,
clearTokens: () => void,
isAuthenticated: () => boolean,
};
Acceptance Criteria
- [ ] All auth-related TypeScript types defined
- [ ] authApi module with all endpoints
- [ ] orgApi module with all endpoints
- [ ] Authorization header injection in base request function
- [ ] 401 handling with automatic token refresh + retry
- [ ] Token storage utility (localStorage)
- [ ] Unit tests for token storage and header injection
Dependencies
- Depends on backend: agent_crew_api#50 (auth config), #51 (local auth), #53 (org management)
Related Issues
Part of Auth & Multi-tenancy epic (Phase 1).
Completed in v0.3.0 release (commit 8ca8e5c). All auth UI features implemented and tested.