mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-23 18:29:21 -05:00
feat: Enhance authentication flow by integrating permissions retrieval and updating related services (#256)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
|
||||
import { AuthState } from '../types';
|
||||
import * as authService from '../services/authService';
|
||||
import { shouldSkipAuth } from '../services/configService';
|
||||
import { getPublicConfig } from '../services/configService';
|
||||
|
||||
// Initial auth state
|
||||
const initialState: AuthState = {
|
||||
@@ -32,7 +32,7 @@ export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
|
||||
useEffect(() => {
|
||||
const loadUser = async () => {
|
||||
// First check if authentication should be skipped
|
||||
const skipAuth = await shouldSkipAuth();
|
||||
const { skipAuth, permissions } = await getPublicConfig();
|
||||
|
||||
if (skipAuth) {
|
||||
// If authentication is disabled, set user as authenticated with a dummy user
|
||||
@@ -42,6 +42,7 @@ export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
|
||||
user: {
|
||||
username: 'guest',
|
||||
isAdmin: true,
|
||||
permissions,
|
||||
},
|
||||
error: null,
|
||||
});
|
||||
|
||||
@@ -26,6 +26,7 @@ export interface PublicConfigResponse {
|
||||
success: boolean;
|
||||
data?: {
|
||||
skipAuth?: boolean;
|
||||
permissions?: any;
|
||||
};
|
||||
message?: string;
|
||||
}
|
||||
@@ -41,7 +42,7 @@ export interface SystemConfigResponse {
|
||||
/**
|
||||
* Get public configuration (skipAuth setting) without authentication
|
||||
*/
|
||||
export const getPublicConfig = async (): Promise<{ skipAuth: boolean }> => {
|
||||
export const getPublicConfig = async (): Promise<{ skipAuth: boolean; permissions?: any }> => {
|
||||
try {
|
||||
const basePath = getBasePath();
|
||||
const response = await fetchWithInterceptors(`${basePath}/public-config`, {
|
||||
@@ -53,7 +54,7 @@ export const getPublicConfig = async (): Promise<{ skipAuth: boolean }> => {
|
||||
|
||||
if (response.ok) {
|
||||
const data: PublicConfigResponse = await response.json();
|
||||
return { skipAuth: data.data?.skipAuth === true };
|
||||
return { skipAuth: data.data?.skipAuth === true, permissions: data.data?.permissions || {} };
|
||||
}
|
||||
|
||||
return { skipAuth: false };
|
||||
|
||||
Reference in New Issue
Block a user