fix: admin auth related fixes

This commit is contained in:
sriram veeraghanta 2024-05-14 20:54:49 +05:30
parent 9b7b23f5a2
commit bcc4524f7f
80 changed files with 606 additions and 360 deletions

View file

@ -1,6 +1,6 @@
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
// store
import { rootStore } from "@/lib/store-context";
// import { rootStore } from "@/lib/store-context";
export abstract class APIService {
protected baseURL: string;
@ -17,14 +17,14 @@ export abstract class APIService {
}
private setupInterceptors() {
this.axiosInstance.interceptors.response.use(
(response) => response,
(error) => {
const store = rootStore;
if (error.response && error.response.status === 401 && store.user.currentUser) store.user.reset();
return Promise.reject(error);
}
);
// this.axiosInstance.interceptors.response.use(
// (response) => response,
// (error) => {
// const store = rootStore;
// if (error.response && error.response.status === 401 && store.user.currentUser) store.user.reset();
// return Promise.reject(error);
// }
// );
}
get<ResponseType>(url: string, params = {}): Promise<AxiosResponse<ResponseType>> {

View file

@ -1,7 +1,7 @@
// services
import { APIService } from "services/api.service";
// helpers
import { API_BASE_URL } from "helpers/common.helper";
// services
import { APIService } from "services/api.service";
type TCsrfTokenResponse = {
csrf_token: string;

View file

@ -13,6 +13,7 @@ export class InstanceService extends APIService {
return this.get<IInstance>("/api/instances/")
.then((response) => response.data)
.catch((error) => {
console.log("error", error);
throw error;
});
}

View file

@ -1,15 +1,25 @@
// helpers
import { API_BASE_URL } from "helpers/common.helper";
// services
import { APIService } from "services/api.service";
// types
import type { IUser } from "@plane/types";
// helpers
import { API_BASE_URL } from "helpers/common.helper";
interface IUserSession extends IUser {
isAuthenticated: boolean;
}
export class UserService extends APIService {
constructor() {
super(API_BASE_URL);
}
async authCheck(): Promise<IUserSession> {
return this.get<any>("/api/instances/admins/me/")
.then((response) => ({ ...response?.data, isAuthenticated: true }))
.catch(() => ({ isAuthenticated: false }));
}
async currentUser(): Promise<IUser> {
return this.get<IUser>("/api/instances/admins/me/")
.then((response) => response?.data)