username and password instead of email and password

This commit is contained in:
2025-11-11 18:47:16 +05:30
parent 3bf0a5839c
commit b2a7df5760
2 changed files with 6 additions and 6 deletions

View File

@@ -13,12 +13,12 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
const [error, setError] = useState<string | null>(null);
/** 🔹 Register new user */
const register = async (username: string, email: string, password: string) => {
const register = async (username: string, password: string) => {
try {
setLoading(true);
setError(null);
const res = await api.post('/auth/register', { username, email, password });
const res = await api.post('/auth/register', { username, password });
return res.data; // returns PublicUser from backend
} catch (err: any) {
console.error('Registration failed:', err);
@@ -29,12 +29,12 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
};
/** 🔹 Login and store JWT token */
const login = async (email: string, password: string) => {
const login = async (username: string, password: string) => {
try {
setLoading(true);
setError(null);
const res = await api.post('/auth/login', { email, password });
const res = await api.post('/auth/login', { username, password });
const { access_token, user } = res.data;
if (access_token) {

View File

@@ -13,8 +13,8 @@ export interface AuthContextModel {
token: string | null;
loading: boolean;
error: string | null;
login: (email: string, password: string) => Promise<void>;
register: (username: string, email: string, password: string) => Promise<void>;
login: (username: string, password: string) => Promise<void>;
register: (username: string, password: string) => Promise<void>;
logout: () => void;
refreshAuthors: () => Promise<void>;
}