first commit

This commit is contained in:
Beyhan Oğur
2026-04-26 21:52:23 +03:00
commit 880f412e2c
2662 changed files with 866266 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
import { baseApi, clearAuthStorage } from "./baseApi";
export interface LoginRequest {
username: string;
password: string;
}
export interface LoginResponse {
message: string;
}
export interface IsAuthEnabledResponse {
is_auth_enabled: boolean;
has_valid_token: boolean;
}
export interface LogoutResponse {
message: string;
}
export const sessionApi = baseApi.injectEndpoints({
overrideExisting: false,
endpoints: (builder) => ({
// Check if auth is enabled
isAuthEnabled: builder.query<IsAuthEnabledResponse, void>({
query: () => ({
url: "/session/is-auth-enabled",
method: "GET",
}),
}),
// Login endpoint
login: builder.mutation<LoginResponse, LoginRequest>({
query: (credentials) => ({
url: "/session/login",
method: "POST",
body: credentials,
}),
invalidatesTags: [],
}),
// Logout endpoint
logout: builder.mutation<LogoutResponse, void>({
query: () => ({
url: "/session/logout",
method: "POST",
}),
// After logout, clear token and all cached data
async onQueryStarted(arg, { queryFulfilled }) {
try {
await queryFulfilled;
} catch {
} finally {
clearAuthStorage();
}
},
invalidatesTags: ["Config", "Providers", "Logs", "VirtualKeys", "Teams", "Customers", "Budgets", "RateLimits"],
}),
}),
});
export const { useIsAuthEnabledQuery, useLoginMutation, useLogoutMutation } = sessionApi;