created proxy for parser backend
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
class AuthService {
|
||||
private API_BASE = '/api/auth'
|
||||
|
||||
private hashPassword(password: string) {
|
||||
// TODO: password hashing
|
||||
return password
|
||||
}
|
||||
|
||||
async login(email: string, password: string) {
|
||||
const response = await fetch(`${this.API_BASE}/login`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
password: this.hashPassword(password),
|
||||
}),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Login failed')
|
||||
}
|
||||
|
||||
return await response.json()
|
||||
}
|
||||
|
||||
async register(name: string, email: string, password: string) {
|
||||
const response = await fetch(`${this.API_BASE}/register`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
name,
|
||||
email,
|
||||
password: this.hashPassword(password),
|
||||
}),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Registration failed')
|
||||
}
|
||||
|
||||
return await response.json()
|
||||
}
|
||||
}
|
||||
|
||||
// Export a singleton instance
|
||||
export const authService = new AuthService()
|
||||
Reference in New Issue
Block a user