username and password instead of email and password
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user