first commit
All checks were successful
CI / backend (push) Successful in 13m19s
CI / frontend (push) Successful in 11m3s
CI / docker (push) Successful in 1m58s

This commit is contained in:
Cauê Faleiros
2026-06-03 16:31:42 -03:00
commit 8c7e5fbbe4
92 changed files with 18226 additions and 0 deletions

62
frontend/src/lib/auth.ts Normal file
View File

@@ -0,0 +1,62 @@
import { apiRequest } from "@/lib/api";
const TOKEN_STORAGE_KEY = "mira_access_token";
export type AuthUser = {
id: string;
email: string;
name: string;
role: "super_admin" | "agency_user" | "client_viewer";
status: string;
};
type LoginResponse = {
access_token: string;
token_type: "Bearer";
user: AuthUser;
};
type MeResponse = {
user: AuthUser;
};
export function getStoredToken() {
return localStorage.getItem(TOKEN_STORAGE_KEY);
}
export function storeToken(token: string) {
localStorage.setItem(TOKEN_STORAGE_KEY, token);
}
export function clearStoredToken() {
localStorage.removeItem(TOKEN_STORAGE_KEY);
}
export async function login(email: string, password: string) {
const response = await apiRequest<LoginResponse>("/auth/login", {
method: "POST",
body: JSON.stringify({ email, password }),
});
storeToken(response.access_token);
return response;
}
export async function acceptInvitation(token: string, name: string, password: string) {
const response = await apiRequest<LoginResponse>("/auth/invitations/accept", {
method: "POST",
body: JSON.stringify({ token, name, password }),
});
storeToken(response.access_token);
return response;
}
export async function loadCurrentUser(token: string) {
const response = await apiRequest<MeResponse>("/me", {
method: "GET",
token,
});
return response.user;
}