34 lines
912 B
TypeScript
34 lines
912 B
TypeScript
import { AxiosInstance } from 'axios';
|
|
import { HttpInstanceFactory } from '../utils/HttpInstanceFactory';
|
|
|
|
export interface IUser {
|
|
jwt: string;
|
|
user: {
|
|
id: number;
|
|
username: string;
|
|
confirmed: boolean;
|
|
blocked: boolean;
|
|
}
|
|
}
|
|
|
|
export class AuthApi {
|
|
private static instance: AuthApi | null = null;
|
|
private httpInstance: AxiosInstance;
|
|
|
|
private constructor() {
|
|
this.httpInstance = HttpInstanceFactory.getBaseInstance();
|
|
}
|
|
|
|
public static getInstance(): AuthApi {
|
|
if (this.instance) return this.instance;
|
|
this.instance = new AuthApi();
|
|
return this.instance;
|
|
}
|
|
|
|
async login(): Promise<IUser> {
|
|
return (await this.httpInstance.post<IUser>(`/auth/local`, {
|
|
identifier: process.env.NEXT_PUBLIC_STRAPI_USER,
|
|
password: process.env.NEXT_PUBLIC_STRAPI_PASSWORD,
|
|
})).data;
|
|
}
|
|
} |