feat: add public instructor profiles
All checks were successful
CI / Validate frontend and API (push) Successful in 54s
CI / Build and publish Docker images (push) Successful in 26s

This commit is contained in:
Cauê Faleiros
2026-09-08 10:50:35 -03:00
parent 07fbc7d009
commit 7b2d25aabb
12 changed files with 372 additions and 7 deletions

View File

@@ -1,12 +1,13 @@
import React, { createContext, useContext, useState, useEffect } from 'react';
import { User, UserRole } from '../types';
import { authApi, clearSession, getSession, saveSession } from '../services/api';
import { ApiUser, authApi, clearSession, getSession, saveSession } from '../services/api';
interface AuthContextType {
user: User | null;
login: (email: string, password: string) => Promise<User | null>;
register: (name: string, email: string, password: string) => Promise<User | null>;
logout: () => void;
updateCurrentUser: (user: ApiUser) => void;
isLoading: boolean;
}
@@ -67,8 +68,14 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
clearSession();
};
const updateCurrentUser = (apiUser: ApiUser) => {
const session = getSession();
if (session) saveSession({ ...session, user: apiUser });
setUser(toFrontendUser(apiUser));
};
return (
<AuthContext.Provider value={{ user, login, register, logout, isLoading }}>
<AuthContext.Provider value={{ user, login, register, logout, updateCurrentUser, isLoading }}>
{children}
</AuthContext.Provider>
);