46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
class AuthService {
|
|
/**
|
|
* Performs user sign in.
|
|
* Mock implementation uses email: ujjwal@sentientgeeks.com and password: Test@123
|
|
*/
|
|
async signIn(emailOrPhone: string, password: string): Promise<string> {
|
|
// Simulating API call delay
|
|
await new Promise<void>((resolve) => setTimeout(() => resolve(), 1000));
|
|
|
|
// Mock credentials check
|
|
if (emailOrPhone.trim() === 'ujjwal@sentientgeeks.com' && password === 'Test@123') {
|
|
return 'mock-access-token';
|
|
}
|
|
|
|
/*
|
|
// REAL API IMPLEMENTATION:
|
|
try {
|
|
const response = await fetch('https://api.yourdomain.com/auth/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
username: emailOrPhone,
|
|
password: password,
|
|
}),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorData = await response.json();
|
|
throw new Error(errorData.message || 'Login failed');
|
|
}
|
|
|
|
const data = await response.json();
|
|
return data.accessToken; // returns the real token
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
*/
|
|
|
|
throw new Error('Invalid email/phone number or password.');
|
|
}
|
|
}
|
|
|
|
export default new AuthService();
|