first implementation

This commit is contained in:
counterweight 2025-12-20 11:12:11 +01:00
parent 79458bcba4
commit 870804e7b9
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
24 changed files with 5485 additions and 184 deletions

View file

@ -10,6 +10,8 @@ export const Permission = {
INCREMENT_COUNTER: "increment_counter",
USE_SUM: "use_sum",
VIEW_AUDIT: "view_audit",
MANAGE_INVITES: "manage_invites",
VIEW_OWN_INVITES: "view_own_invites",
} as const;
export type PermissionType = typeof Permission[keyof typeof Permission];
@ -25,7 +27,7 @@ interface AuthContextType {
user: User | null;
isLoading: boolean;
login: (email: string, password: string) => Promise<void>;
register: (email: string, password: string) => Promise<void>;
register: (email: string, password: string, inviteIdentifier: string) => Promise<void>;
logout: () => Promise<void>;
hasPermission: (permission: PermissionType) => boolean;
hasRole: (role: string) => boolean;
@ -65,9 +67,13 @@ export function AuthProvider({ children }: { children: ReactNode }) {
}
};
const register = async (email: string, password: string) => {
const register = async (email: string, password: string, inviteIdentifier: string) => {
try {
const userData = await api.post<User>("/api/auth/register", { email, password });
const userData = await api.post<User>("/api/auth/register", {
email,
password,
invite_identifier: inviteIdentifier,
});
setUser(userData);
} catch (err) {
if (err instanceof ApiError) {