analytica-frontend-lib 1.0.73 → 1.0.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Auth/AuthProvider/index.d.mts +3 -0
- package/dist/Auth/AuthProvider/index.d.ts +3 -0
- package/dist/Auth/AuthProvider/index.js +211 -0
- package/dist/Auth/AuthProvider/index.js.map +1 -0
- package/dist/Auth/AuthProvider/index.mjs +187 -0
- package/dist/Auth/AuthProvider/index.mjs.map +1 -0
- package/dist/Auth/ProtectedRoute/index.d.mts +3 -0
- package/dist/Auth/ProtectedRoute/index.d.ts +3 -0
- package/dist/Auth/ProtectedRoute/index.js +211 -0
- package/dist/Auth/ProtectedRoute/index.js.map +1 -0
- package/dist/Auth/ProtectedRoute/index.mjs +187 -0
- package/dist/Auth/ProtectedRoute/index.mjs.map +1 -0
- package/dist/Auth/PublicRoute/index.d.mts +3 -0
- package/dist/Auth/PublicRoute/index.d.ts +3 -0
- package/dist/Auth/PublicRoute/index.js +211 -0
- package/dist/Auth/PublicRoute/index.js.map +1 -0
- package/dist/Auth/PublicRoute/index.mjs +187 -0
- package/dist/Auth/PublicRoute/index.mjs.map +1 -0
- package/dist/Auth/index.d.mts +106 -19
- package/dist/Auth/index.d.ts +106 -19
- package/dist/Auth/index.js +21 -0
- package/dist/Auth/index.js.map +1 -1
- package/dist/Auth/index.mjs +21 -0
- package/dist/Auth/index.mjs.map +1 -1
- package/dist/Auth/useAuth/index.d.mts +3 -0
- package/dist/Auth/useAuth/index.d.ts +3 -0
- package/dist/Auth/useAuth/index.js +211 -0
- package/dist/Auth/useAuth/index.js.map +1 -0
- package/dist/Auth/useAuth/index.mjs +187 -0
- package/dist/Auth/useAuth/index.mjs.map +1 -0
- package/dist/Auth/useAuthGuard/index.d.mts +3 -0
- package/dist/Auth/useAuthGuard/index.d.ts +3 -0
- package/dist/Auth/useAuthGuard/index.js +211 -0
- package/dist/Auth/useAuthGuard/index.js.map +1 -0
- package/dist/Auth/useAuthGuard/index.mjs +187 -0
- package/dist/Auth/useAuthGuard/index.mjs.map +1 -0
- package/dist/Auth/useRouteAuth/index.d.mts +3 -0
- package/dist/Auth/useRouteAuth/index.d.ts +3 -0
- package/dist/Auth/useRouteAuth/index.js +211 -0
- package/dist/Auth/useRouteAuth/index.js.map +1 -0
- package/dist/Auth/useRouteAuth/index.mjs +187 -0
- package/dist/Auth/useRouteAuth/index.mjs.map +1 -0
- package/dist/Auth/useUrlAuthentication/index.d.mts +58 -0
- package/dist/Auth/useUrlAuthentication/index.d.ts +58 -0
- package/dist/Auth/useUrlAuthentication/index.js +94 -0
- package/dist/Auth/useUrlAuthentication/index.js.map +1 -0
- package/dist/Auth/useUrlAuthentication/index.mjs +69 -0
- package/dist/Auth/useUrlAuthentication/index.mjs.map +1 -0
- package/dist/Auth/withAuth/index.d.mts +3 -0
- package/dist/Auth/withAuth/index.d.ts +3 -0
- package/dist/Auth/withAuth/index.js +211 -0
- package/dist/Auth/withAuth/index.js.map +1 -0
- package/dist/Auth/withAuth/index.mjs +187 -0
- package/dist/Auth/withAuth/index.mjs.map +1 -0
- package/dist/Auth/zustandAuthAdapter/index.d.mts +75 -0
- package/dist/Auth/zustandAuthAdapter/index.d.ts +75 -0
- package/dist/Auth/zustandAuthAdapter/index.js +70 -0
- package/dist/Auth/zustandAuthAdapter/index.js.map +1 -0
- package/dist/Auth/zustandAuthAdapter/index.mjs +45 -0
- package/dist/Auth/zustandAuthAdapter/index.mjs.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +133 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +131 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Auth/Auth.tsx"],"sourcesContent":["import {\n createContext,\n useContext,\n useEffect,\n useState,\n ReactNode,\n ComponentType,\n useCallback,\n useMemo,\n} from 'react';\nimport { useLocation, Navigate } from 'react-router-dom';\n\n/**\n * Interface for basic authentication tokens\n *\n * @interface AuthTokens\n * @property {string} token - Main authentication token\n * @property {string} refreshToken - Token used to refresh the main token\n * @property {unknown} [key] - Additional properties that can be included\n */\nexport interface AuthTokens {\n token: string;\n refreshToken: string;\n [key: string]: unknown;\n}\n\n/**\n * Interface for basic user information\n *\n * @interface AuthUser\n * @property {string} id - Unique user identifier\n * @property {string} [name] - Optional user name\n * @property {string} [email] - Optional user email\n * @property {unknown} [key] - Additional user properties\n */\nexport interface AuthUser {\n id: string;\n name?: string;\n email?: string;\n [key: string]: unknown;\n}\n\n/**\n * Interface for basic session information\n *\n * @interface SessionInfo\n * @property {string} [institutionId] - Optional institution identifier\n * @property {string} [profileId] - Optional profile identifier\n * @property {string} [schoolId] - Optional school identifier\n * @property {string} [schoolYearId] - Optional school year identifier\n * @property {string} [classId] - Optional class identifier\n * @property {unknown} [key] - Additional session properties\n */\nexport interface SessionInfo {\n institutionId?: string;\n profileId?: string;\n schoolId?: string;\n schoolYearId?: string;\n classId?: string;\n [key: string]: unknown;\n}\n\n/**\n * Interface for authentication state\n *\n * @interface AuthState\n * @property {boolean} isAuthenticated - Whether the user is authenticated\n * @property {boolean} isLoading - Whether authentication is being checked\n * @property {AuthUser | null} [user] - Current user information\n * @property {SessionInfo | null} [sessionInfo] - Current session information\n * @property {AuthTokens | null} [tokens] - Current authentication tokens\n */\nexport interface AuthState {\n isAuthenticated: boolean;\n isLoading: boolean;\n user?: AuthUser | null;\n sessionInfo?: SessionInfo | null;\n tokens?: AuthTokens | null;\n}\n\n/**\n * Interface for authentication context functions and state\n *\n * @interface AuthContextType\n * @extends {AuthState}\n * @property {() => Promise<boolean>} checkAuth - Function to check authentication status\n * @property {() => void} signOut - Function to sign out the user\n */\nexport interface AuthContextType extends AuthState {\n checkAuth: () => Promise<boolean>;\n signOut: () => void;\n}\n\n/**\n * Authentication context for React components\n *\n * @private\n */\nconst AuthContext = createContext<AuthContextType | undefined>(undefined);\n\n/**\n * Props for the AuthProvider component\n *\n * @interface AuthProviderProps\n * @property {ReactNode} children - Child components\n * @property {() => Promise<boolean> | boolean} [checkAuthFn] - Function to check if user is authenticated\n * @property {() => void} [signOutFn] - Function to handle logout\n * @property {Partial<AuthState>} [initialAuthState] - Initial authentication state\n * @property {() => AuthUser | null | undefined} [getUserFn] - Function to get user data\n * @property {() => SessionInfo | null | undefined} [getSessionFn] - Function to get session info\n * @property {() => AuthTokens | null | undefined} [getTokensFn] - Function to get tokens\n */\nexport interface AuthProviderProps {\n children: ReactNode;\n /**\n * Função para verificar se o usuário está autenticado\n * Deve retornar uma Promise<boolean>\n */\n checkAuthFn?: () => Promise<boolean> | boolean;\n /**\n * Função para fazer logout\n */\n signOutFn?: () => void;\n /**\n * Estado de autenticação inicial\n */\n initialAuthState?: Partial<AuthState>;\n /**\n * Função para obter dados do usuário (opcional)\n */\n getUserFn?: () => AuthUser | null | undefined;\n /**\n * Função para obter informações da sessão (opcional)\n */\n getSessionFn?: () => SessionInfo | null | undefined;\n /**\n * Função para obter tokens (opcional)\n */\n getTokensFn?: () => AuthTokens | null | undefined;\n}\n\n/**\n * Authentication provider that manages global auth state\n * Compatible with any store (Zustand, Redux, Context, etc.)\n *\n * @param {AuthProviderProps} props - The provider props\n * @returns {JSX.Element} The provider component\n *\n * @example\n * ```tsx\n * <AuthProvider\n * checkAuthFn={checkAuthFunction}\n * signOutFn={signOutFunction}\n * getUserFn={getUserFunction}\n * >\n * <App />\n * </AuthProvider>\n * ```\n */\nexport const AuthProvider = ({\n children,\n checkAuthFn,\n signOutFn,\n initialAuthState = {},\n getUserFn,\n getSessionFn,\n getTokensFn,\n}: AuthProviderProps) => {\n const [authState, setAuthState] = useState<AuthState>({\n isAuthenticated: false,\n isLoading: true,\n ...initialAuthState,\n });\n\n /**\n * Check authentication status and update state accordingly\n *\n * @returns {Promise<boolean>} Promise that resolves to authentication status\n */\n const checkAuth = useCallback(async (): Promise<boolean> => {\n try {\n setAuthState((prev) => ({ ...prev, isLoading: true }));\n\n // Se não há função de verificação, assume como não autenticado\n if (!checkAuthFn) {\n setAuthState((prev) => ({\n ...prev,\n isAuthenticated: false,\n isLoading: false,\n }));\n return false;\n }\n\n const isAuth = await checkAuthFn();\n\n setAuthState((prev) => ({\n ...prev,\n isAuthenticated: isAuth,\n isLoading: false,\n user: getUserFn ? getUserFn() : prev.user,\n sessionInfo: getSessionFn ? getSessionFn() : prev.sessionInfo,\n tokens: getTokensFn ? getTokensFn() : prev.tokens,\n }));\n\n return isAuth;\n } catch (error) {\n console.error('Erro ao verificar autenticação:', error);\n setAuthState((prev) => ({\n ...prev,\n isAuthenticated: false,\n isLoading: false,\n }));\n return false;\n }\n }, [checkAuthFn, getUserFn, getSessionFn, getTokensFn]);\n\n /**\n * Sign out the current user and clear auth state\n *\n * @returns {void}\n */\n const signOut = useCallback(() => {\n if (signOutFn) {\n signOutFn();\n }\n setAuthState((prev) => ({\n ...prev,\n isAuthenticated: false,\n user: undefined,\n sessionInfo: undefined,\n tokens: undefined,\n }));\n }, [signOutFn]);\n\n useEffect(() => {\n checkAuth();\n }, [checkAuth]);\n\n const contextValue = useMemo(\n (): AuthContextType => ({\n ...authState,\n checkAuth,\n signOut,\n }),\n [authState, checkAuth, signOut]\n );\n\n return (\n <AuthContext.Provider value={contextValue}>{children}</AuthContext.Provider>\n );\n};\n\n/**\n * Hook to use the authentication context\n *\n * @throws {Error} When used outside of AuthProvider\n * @returns {AuthContextType} The authentication context\n *\n * @example\n * ```tsx\n * const { isAuthenticated, user, signOut } = useAuth();\n * ```\n */\nexport const useAuth = (): AuthContextType => {\n const context = useContext(AuthContext);\n if (context === undefined) {\n throw new Error('useAuth deve ser usado dentro de um AuthProvider');\n }\n return context;\n};\n\n/**\n * Props for the ProtectedRoute component\n *\n * @interface ProtectedRouteProps\n * @property {ReactNode} children - Components to render when authenticated\n * @property {string} [redirectTo] - Path to redirect when not authenticated (default: '/')\n * @property {ReactNode} [loadingComponent] - Custom loading component\n * @property {(authState: AuthState) => boolean} [additionalCheck] - Additional authentication check\n */\nexport interface ProtectedRouteProps {\n children: ReactNode;\n /**\n * Path para redirecionamento quando não autenticado\n */\n redirectTo?: string;\n /**\n * Componente de loading personalizado\n */\n loadingComponent?: ReactNode;\n /**\n * Função adicional de verificação (ex: verificar permissões específicas)\n */\n additionalCheck?: (authState: AuthState) => boolean;\n}\n\n/**\n * Componente para proteger rotas que requerem autenticação\n *\n * @example\n * ```tsx\n * <ProtectedRoute redirectTo=\"/login\">\n * <PainelPage />\n * </ProtectedRoute>\n * ```\n */\nexport const ProtectedRoute = ({\n children,\n redirectTo = '/',\n loadingComponent,\n additionalCheck,\n}: ProtectedRouteProps) => {\n const { isAuthenticated, isLoading, ...authState } = useAuth();\n\n // Componente de loading padrão\n const defaultLoadingComponent = (\n <div className=\"flex items-center justify-center min-h-screen\">\n <div className=\"text-text-950 text-lg\">Carregando...</div>\n </div>\n );\n\n // Mostrar loading enquanto verifica autenticação\n if (isLoading) {\n return <>{loadingComponent || defaultLoadingComponent}</>;\n }\n\n // Verificar autenticação básica\n if (!isAuthenticated) {\n if (typeof window !== 'undefined') {\n const rootDomain = getRootDomain();\n // Only redirect if the root domain is different from current location\n const currentLocation = `${window.location.protocol}//${window.location.hostname}${window.location.port ? ':' + window.location.port : ''}`;\n if (rootDomain !== currentLocation) {\n window.location.href = rootDomain;\n return null;\n }\n }\n return <Navigate to={redirectTo} replace />;\n }\n\n // Verificação adicional (ex: permissões)\n if (\n additionalCheck &&\n !additionalCheck({ isAuthenticated, isLoading, ...authState })\n ) {\n return <Navigate to={redirectTo} replace />;\n }\n\n return <>{children}</>;\n};\n\n/**\n * Props for the PublicRoute component\n *\n * @interface PublicRouteProps\n * @property {ReactNode} children - Components to render\n * @property {string} [redirectTo] - Path to redirect to (default: '/painel')\n * @property {boolean} [redirectIfAuthenticated] - Whether to redirect if authenticated\n * @property {boolean} [checkAuthBeforeRender] - Whether to check auth before rendering\n */\nexport interface PublicRouteProps {\n children: ReactNode;\n /**\n * Path para redirecionamento\n */\n redirectTo?: string;\n /**\n * Se deve redirecionar quando usuário estiver autenticado\n */\n redirectIfAuthenticated?: boolean;\n /**\n * Se deve verificar autenticação antes de renderizar\n */\n checkAuthBeforeRender?: boolean;\n}\n\n/**\n * Componente para rotas públicas (login, recuperação de senha, etc.)\n * Opcionalmente redireciona se o usuário já estiver autenticado\n *\n * @example\n * ```tsx\n * <PublicRoute redirectTo=\"/painel\" redirectIfAuthenticated={true}>\n * <LoginPage />\n * </PublicRoute>\n * ```\n */\nexport const PublicRoute = ({\n children,\n redirectTo = '/painel',\n redirectIfAuthenticated = false,\n checkAuthBeforeRender = false,\n}: PublicRouteProps) => {\n const { isAuthenticated, isLoading } = useAuth();\n\n // Se deve aguardar verificação de auth antes de renderizar\n if (checkAuthBeforeRender && isLoading) {\n return (\n <div className=\"flex items-center justify-center min-h-screen\">\n <div className=\"text-text-950 text-lg\">Carregando...</div>\n </div>\n );\n }\n\n // Redirecionar se já autenticado e configurado para isso\n if (isAuthenticated && redirectIfAuthenticated) {\n return <Navigate to={redirectTo} replace />;\n }\n\n return <>{children}</>;\n};\n\n/**\n * Higher-Order Component to protect components with authentication\n *\n * @template P - Component props type\n * @param {ComponentType<P>} Component - Component to wrap with authentication\n * @param {Omit<ProtectedRouteProps, 'children'>} [options] - Protection options\n * @returns {(props: P) => JSX.Element} Wrapped component\n *\n * @example\n * ```tsx\n * const ProtectedComponent = withAuth(MyComponent, {\n * redirectTo: \"/login\",\n * loadingComponent: <CustomSpinner />\n * });\n * ```\n */\nexport const withAuth = <P extends object>(\n Component: ComponentType<P>,\n options: Omit<ProtectedRouteProps, 'children'> = {}\n) => {\n return (props: P) => (\n <ProtectedRoute {...options}>\n <Component {...props} />\n </ProtectedRoute>\n );\n};\n\n/**\n * Hook for authentication guard with custom checks\n *\n * @param {object} [options] - Guard options\n * @param {boolean} [options.requireAuth=true] - Whether authentication is required\n * @param {(authState: AuthState) => boolean} [options.customCheck] - Custom check function\n * @returns {object} Guard result with canAccess, isLoading, and authState\n *\n * @example\n * ```tsx\n * const { canAccess, isLoading } = useAuthGuard({\n * requireAuth: true,\n * customCheck: (authState) => authState.user?.role === 'admin'\n * });\n * ```\n */\nexport const useAuthGuard = (\n options: {\n requireAuth?: boolean;\n customCheck?: (authState: AuthState) => boolean;\n } = {}\n) => {\n const authState = useAuth();\n const { requireAuth = true, customCheck } = options;\n\n const canAccess =\n !authState.isLoading &&\n (requireAuth\n ? authState.isAuthenticated && (!customCheck || customCheck(authState))\n : !authState.isAuthenticated || !customCheck || customCheck(authState));\n\n return {\n canAccess,\n isLoading: authState.isLoading,\n authState,\n };\n};\n\n/**\n * Hook to check authentication on specific routes\n * Useful for conditional checks within components\n *\n * @param {string} [fallbackPath='/'] - Path to redirect when not authenticated\n * @returns {object} Object with isAuthenticated, isLoading, and redirectToLogin function\n *\n * @example\n * ```tsx\n * const { isAuthenticated, redirectToLogin } = useRouteAuth();\n *\n * if (!isAuthenticated) {\n * return redirectToLogin();\n * }\n * ```\n */\nexport const useRouteAuth = (fallbackPath = '/') => {\n const { isAuthenticated, isLoading } = useAuth();\n const location = useLocation();\n\n const redirectToLogin = () => (\n <Navigate to={fallbackPath} state={{ from: location }} replace />\n );\n\n return {\n isAuthenticated,\n isLoading,\n redirectToLogin,\n };\n};\n\n/**\n * Get the root domain from the current window location\n * Handles localhost and subdomain cases\n *\n * @private\n * @returns {string} The root domain URL\n */\nconst getRootDomain = () => {\n const { hostname, protocol, port } = window.location;\n const portStr = port ? ':' + port : '';\n if (hostname === 'localhost') {\n return `${protocol}//${hostname}${portStr}`;\n }\n const parts = hostname.split('.');\n // Only treat as subdomain if there are 3+ parts (e.g., subdomain.example.com)\n if (parts.length > 2) {\n // Return the last 2 parts as the root domain (example.com)\n const base = parts.slice(-2).join('.');\n return `${protocol}//${base}${portStr}`;\n }\n // For 2-part domains (example.com) or single domains, return as-is\n return `${protocol}//${hostname}${portStr}`;\n};\n\nexport default {\n AuthProvider,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oBAAC,YAAS,IAAI,cAAc,OAAO,EAAE,MAAM,SAAS,GAAG,SAAO,MAAC;AAGjE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AASA,IAAM,gBAAgB,MAAM;AAC1B,QAAM,EAAE,UAAU,UAAU,KAAK,IAAI,OAAO;AAC5C,QAAM,UAAU,OAAO,MAAM,OAAO;AACpC,MAAI,aAAa,aAAa;AAC5B,WAAO,GAAG,QAAQ,KAAK,QAAQ,GAAG,OAAO;AAAA,EAC3C;AACA,QAAM,QAAQ,SAAS,MAAM,GAAG;AAEhC,MAAI,MAAM,SAAS,GAAG;AAEpB,UAAM,OAAO,MAAM,MAAM,EAAE,EAAE,KAAK,GAAG;AACrC,WAAO,GAAG,QAAQ,KAAK,IAAI,GAAG,OAAO;AAAA,EACvC;AAEA,SAAO,GAAG,QAAQ,KAAK,QAAQ,GAAG,OAAO;AAC3C;AAEA,IAAO,eAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic adapter for integrating AuthProvider with Zustand stores
|
|
3
|
+
* Users should import this file and pass their store instance
|
|
4
|
+
*
|
|
5
|
+
* @template S - Zustand store type that contains auth-related state
|
|
6
|
+
* @param {object} useAuthStore - Zustand store hook with getState method
|
|
7
|
+
* @param {() => S} useAuthStore.getState - Function to get current store state
|
|
8
|
+
* @returns {object} Adapter object with auth functions
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Define your Zustand store type
|
|
13
|
+
* interface AuthStore {
|
|
14
|
+
* sessionInfo?: SessionInfo;
|
|
15
|
+
* tokens?: AuthTokens;
|
|
16
|
+
* user?: AuthUser;
|
|
17
|
+
* signOut: () => void;
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // Create the adapter
|
|
21
|
+
* const authAdapter = createZustandAuthAdapter(useAuthStore);
|
|
22
|
+
*
|
|
23
|
+
* // Use with AuthProvider
|
|
24
|
+
* <AuthProvider
|
|
25
|
+
* checkAuthFn={authAdapter.checkAuth}
|
|
26
|
+
* signOutFn={authAdapter.signOut}
|
|
27
|
+
* getUserFn={authAdapter.getUser}
|
|
28
|
+
* getSessionFn={authAdapter.getSessionInfo}
|
|
29
|
+
* getTokensFn={authAdapter.getTokens}
|
|
30
|
+
* >
|
|
31
|
+
* <App />
|
|
32
|
+
* </AuthProvider>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function createZustandAuthAdapter<S extends {
|
|
36
|
+
sessionInfo?: unknown;
|
|
37
|
+
tokens?: unknown;
|
|
38
|
+
user?: unknown;
|
|
39
|
+
signOut?: () => void;
|
|
40
|
+
}>(useAuthStore: {
|
|
41
|
+
getState: () => S;
|
|
42
|
+
}): {
|
|
43
|
+
/**
|
|
44
|
+
* Check if the user is authenticated based on sessionInfo and tokens
|
|
45
|
+
*
|
|
46
|
+
* @returns {Promise<boolean>} Promise that resolves to authentication status
|
|
47
|
+
*/
|
|
48
|
+
checkAuth: () => Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Get the current user from the store
|
|
51
|
+
*
|
|
52
|
+
* @returns {unknown} Current user data from the store
|
|
53
|
+
*/
|
|
54
|
+
getUser: () => unknown;
|
|
55
|
+
/**
|
|
56
|
+
* Get the current session information from the store
|
|
57
|
+
*
|
|
58
|
+
* @returns {unknown} Current session info from the store
|
|
59
|
+
*/
|
|
60
|
+
getSessionInfo: () => unknown;
|
|
61
|
+
/**
|
|
62
|
+
* Get the current authentication tokens from the store
|
|
63
|
+
*
|
|
64
|
+
* @returns {unknown} Current tokens from the store
|
|
65
|
+
*/
|
|
66
|
+
getTokens: () => unknown;
|
|
67
|
+
/**
|
|
68
|
+
* Sign out the user by calling the store's signOut function if available
|
|
69
|
+
*
|
|
70
|
+
* @returns {void}
|
|
71
|
+
*/
|
|
72
|
+
signOut: () => void;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export { createZustandAuthAdapter };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic adapter for integrating AuthProvider with Zustand stores
|
|
3
|
+
* Users should import this file and pass their store instance
|
|
4
|
+
*
|
|
5
|
+
* @template S - Zustand store type that contains auth-related state
|
|
6
|
+
* @param {object} useAuthStore - Zustand store hook with getState method
|
|
7
|
+
* @param {() => S} useAuthStore.getState - Function to get current store state
|
|
8
|
+
* @returns {object} Adapter object with auth functions
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Define your Zustand store type
|
|
13
|
+
* interface AuthStore {
|
|
14
|
+
* sessionInfo?: SessionInfo;
|
|
15
|
+
* tokens?: AuthTokens;
|
|
16
|
+
* user?: AuthUser;
|
|
17
|
+
* signOut: () => void;
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // Create the adapter
|
|
21
|
+
* const authAdapter = createZustandAuthAdapter(useAuthStore);
|
|
22
|
+
*
|
|
23
|
+
* // Use with AuthProvider
|
|
24
|
+
* <AuthProvider
|
|
25
|
+
* checkAuthFn={authAdapter.checkAuth}
|
|
26
|
+
* signOutFn={authAdapter.signOut}
|
|
27
|
+
* getUserFn={authAdapter.getUser}
|
|
28
|
+
* getSessionFn={authAdapter.getSessionInfo}
|
|
29
|
+
* getTokensFn={authAdapter.getTokens}
|
|
30
|
+
* >
|
|
31
|
+
* <App />
|
|
32
|
+
* </AuthProvider>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function createZustandAuthAdapter<S extends {
|
|
36
|
+
sessionInfo?: unknown;
|
|
37
|
+
tokens?: unknown;
|
|
38
|
+
user?: unknown;
|
|
39
|
+
signOut?: () => void;
|
|
40
|
+
}>(useAuthStore: {
|
|
41
|
+
getState: () => S;
|
|
42
|
+
}): {
|
|
43
|
+
/**
|
|
44
|
+
* Check if the user is authenticated based on sessionInfo and tokens
|
|
45
|
+
*
|
|
46
|
+
* @returns {Promise<boolean>} Promise that resolves to authentication status
|
|
47
|
+
*/
|
|
48
|
+
checkAuth: () => Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Get the current user from the store
|
|
51
|
+
*
|
|
52
|
+
* @returns {unknown} Current user data from the store
|
|
53
|
+
*/
|
|
54
|
+
getUser: () => unknown;
|
|
55
|
+
/**
|
|
56
|
+
* Get the current session information from the store
|
|
57
|
+
*
|
|
58
|
+
* @returns {unknown} Current session info from the store
|
|
59
|
+
*/
|
|
60
|
+
getSessionInfo: () => unknown;
|
|
61
|
+
/**
|
|
62
|
+
* Get the current authentication tokens from the store
|
|
63
|
+
*
|
|
64
|
+
* @returns {unknown} Current tokens from the store
|
|
65
|
+
*/
|
|
66
|
+
getTokens: () => unknown;
|
|
67
|
+
/**
|
|
68
|
+
* Sign out the user by calling the store's signOut function if available
|
|
69
|
+
*
|
|
70
|
+
* @returns {void}
|
|
71
|
+
*/
|
|
72
|
+
signOut: () => void;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export { createZustandAuthAdapter };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/components/Auth/zustandAuthAdapter.ts
|
|
21
|
+
var zustandAuthAdapter_exports = {};
|
|
22
|
+
__export(zustandAuthAdapter_exports, {
|
|
23
|
+
createZustandAuthAdapter: () => createZustandAuthAdapter
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(zustandAuthAdapter_exports);
|
|
26
|
+
function createZustandAuthAdapter(useAuthStore) {
|
|
27
|
+
return {
|
|
28
|
+
/**
|
|
29
|
+
* Check if the user is authenticated based on sessionInfo and tokens
|
|
30
|
+
*
|
|
31
|
+
* @returns {Promise<boolean>} Promise that resolves to authentication status
|
|
32
|
+
*/
|
|
33
|
+
checkAuth: async () => {
|
|
34
|
+
const { sessionInfo, tokens } = useAuthStore.getState();
|
|
35
|
+
return Boolean(sessionInfo && tokens);
|
|
36
|
+
},
|
|
37
|
+
/**
|
|
38
|
+
* Get the current user from the store
|
|
39
|
+
*
|
|
40
|
+
* @returns {unknown} Current user data from the store
|
|
41
|
+
*/
|
|
42
|
+
getUser: () => useAuthStore.getState().user,
|
|
43
|
+
/**
|
|
44
|
+
* Get the current session information from the store
|
|
45
|
+
*
|
|
46
|
+
* @returns {unknown} Current session info from the store
|
|
47
|
+
*/
|
|
48
|
+
getSessionInfo: () => useAuthStore.getState().sessionInfo,
|
|
49
|
+
/**
|
|
50
|
+
* Get the current authentication tokens from the store
|
|
51
|
+
*
|
|
52
|
+
* @returns {unknown} Current tokens from the store
|
|
53
|
+
*/
|
|
54
|
+
getTokens: () => useAuthStore.getState().tokens,
|
|
55
|
+
/**
|
|
56
|
+
* Sign out the user by calling the store's signOut function if available
|
|
57
|
+
*
|
|
58
|
+
* @returns {void}
|
|
59
|
+
*/
|
|
60
|
+
signOut: () => {
|
|
61
|
+
const signOutFn = useAuthStore.getState().signOut;
|
|
62
|
+
if (typeof signOutFn === "function") signOutFn();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
createZustandAuthAdapter
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Auth/zustandAuthAdapter.ts"],"sourcesContent":["/**\n * Generic adapter for integrating AuthProvider with Zustand stores\n * Users should import this file and pass their store instance\n *\n * @template S - Zustand store type that contains auth-related state\n * @param {object} useAuthStore - Zustand store hook with getState method\n * @param {() => S} useAuthStore.getState - Function to get current store state\n * @returns {object} Adapter object with auth functions\n *\n * @example\n * ```typescript\n * // Define your Zustand store type\n * interface AuthStore {\n * sessionInfo?: SessionInfo;\n * tokens?: AuthTokens;\n * user?: AuthUser;\n * signOut: () => void;\n * }\n *\n * // Create the adapter\n * const authAdapter = createZustandAuthAdapter(useAuthStore);\n *\n * // Use with AuthProvider\n * <AuthProvider\n * checkAuthFn={authAdapter.checkAuth}\n * signOutFn={authAdapter.signOut}\n * getUserFn={authAdapter.getUser}\n * getSessionFn={authAdapter.getSessionInfo}\n * getTokensFn={authAdapter.getTokens}\n * >\n * <App />\n * </AuthProvider>\n * ```\n */\nexport function createZustandAuthAdapter<\n S extends {\n sessionInfo?: unknown;\n tokens?: unknown;\n user?: unknown;\n signOut?: () => void;\n },\n>(useAuthStore: { getState: () => S }) {\n return {\n /**\n * Check if the user is authenticated based on sessionInfo and tokens\n *\n * @returns {Promise<boolean>} Promise that resolves to authentication status\n */\n checkAuth: async (): Promise<boolean> => {\n const { sessionInfo, tokens } = useAuthStore.getState();\n return Boolean(sessionInfo && tokens);\n },\n /**\n * Get the current user from the store\n *\n * @returns {unknown} Current user data from the store\n */\n getUser: () => useAuthStore.getState().user,\n /**\n * Get the current session information from the store\n *\n * @returns {unknown} Current session info from the store\n */\n getSessionInfo: () => useAuthStore.getState().sessionInfo,\n /**\n * Get the current authentication tokens from the store\n *\n * @returns {unknown} Current tokens from the store\n */\n getTokens: () => useAuthStore.getState().tokens,\n /**\n * Sign out the user by calling the store's signOut function if available\n *\n * @returns {void}\n */\n signOut: () => {\n const signOutFn = useAuthStore.getState().signOut;\n if (typeof signOutFn === 'function') signOutFn();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkCO,SAAS,yBAOd,cAAqC;AACrC,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAML,WAAW,YAA8B;AACvC,YAAM,EAAE,aAAa,OAAO,IAAI,aAAa,SAAS;AACtD,aAAO,QAAQ,eAAe,MAAM;AAAA,IACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,SAAS,MAAM,aAAa,SAAS,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMvC,gBAAgB,MAAM,aAAa,SAAS,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAM9C,WAAW,MAAM,aAAa,SAAS,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMzC,SAAS,MAAM;AACb,YAAM,YAAY,aAAa,SAAS,EAAE;AAC1C,UAAI,OAAO,cAAc,WAAY,WAAU;AAAA,IACjD;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/components/Auth/zustandAuthAdapter.ts
|
|
2
|
+
function createZustandAuthAdapter(useAuthStore) {
|
|
3
|
+
return {
|
|
4
|
+
/**
|
|
5
|
+
* Check if the user is authenticated based on sessionInfo and tokens
|
|
6
|
+
*
|
|
7
|
+
* @returns {Promise<boolean>} Promise that resolves to authentication status
|
|
8
|
+
*/
|
|
9
|
+
checkAuth: async () => {
|
|
10
|
+
const { sessionInfo, tokens } = useAuthStore.getState();
|
|
11
|
+
return Boolean(sessionInfo && tokens);
|
|
12
|
+
},
|
|
13
|
+
/**
|
|
14
|
+
* Get the current user from the store
|
|
15
|
+
*
|
|
16
|
+
* @returns {unknown} Current user data from the store
|
|
17
|
+
*/
|
|
18
|
+
getUser: () => useAuthStore.getState().user,
|
|
19
|
+
/**
|
|
20
|
+
* Get the current session information from the store
|
|
21
|
+
*
|
|
22
|
+
* @returns {unknown} Current session info from the store
|
|
23
|
+
*/
|
|
24
|
+
getSessionInfo: () => useAuthStore.getState().sessionInfo,
|
|
25
|
+
/**
|
|
26
|
+
* Get the current authentication tokens from the store
|
|
27
|
+
*
|
|
28
|
+
* @returns {unknown} Current tokens from the store
|
|
29
|
+
*/
|
|
30
|
+
getTokens: () => useAuthStore.getState().tokens,
|
|
31
|
+
/**
|
|
32
|
+
* Sign out the user by calling the store's signOut function if available
|
|
33
|
+
*
|
|
34
|
+
* @returns {void}
|
|
35
|
+
*/
|
|
36
|
+
signOut: () => {
|
|
37
|
+
const signOutFn = useAuthStore.getState().signOut;
|
|
38
|
+
if (typeof signOutFn === "function") signOutFn();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
createZustandAuthAdapter
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Auth/zustandAuthAdapter.ts"],"sourcesContent":["/**\n * Generic adapter for integrating AuthProvider with Zustand stores\n * Users should import this file and pass their store instance\n *\n * @template S - Zustand store type that contains auth-related state\n * @param {object} useAuthStore - Zustand store hook with getState method\n * @param {() => S} useAuthStore.getState - Function to get current store state\n * @returns {object} Adapter object with auth functions\n *\n * @example\n * ```typescript\n * // Define your Zustand store type\n * interface AuthStore {\n * sessionInfo?: SessionInfo;\n * tokens?: AuthTokens;\n * user?: AuthUser;\n * signOut: () => void;\n * }\n *\n * // Create the adapter\n * const authAdapter = createZustandAuthAdapter(useAuthStore);\n *\n * // Use with AuthProvider\n * <AuthProvider\n * checkAuthFn={authAdapter.checkAuth}\n * signOutFn={authAdapter.signOut}\n * getUserFn={authAdapter.getUser}\n * getSessionFn={authAdapter.getSessionInfo}\n * getTokensFn={authAdapter.getTokens}\n * >\n * <App />\n * </AuthProvider>\n * ```\n */\nexport function createZustandAuthAdapter<\n S extends {\n sessionInfo?: unknown;\n tokens?: unknown;\n user?: unknown;\n signOut?: () => void;\n },\n>(useAuthStore: { getState: () => S }) {\n return {\n /**\n * Check if the user is authenticated based on sessionInfo and tokens\n *\n * @returns {Promise<boolean>} Promise that resolves to authentication status\n */\n checkAuth: async (): Promise<boolean> => {\n const { sessionInfo, tokens } = useAuthStore.getState();\n return Boolean(sessionInfo && tokens);\n },\n /**\n * Get the current user from the store\n *\n * @returns {unknown} Current user data from the store\n */\n getUser: () => useAuthStore.getState().user,\n /**\n * Get the current session information from the store\n *\n * @returns {unknown} Current session info from the store\n */\n getSessionInfo: () => useAuthStore.getState().sessionInfo,\n /**\n * Get the current authentication tokens from the store\n *\n * @returns {unknown} Current tokens from the store\n */\n getTokens: () => useAuthStore.getState().tokens,\n /**\n * Sign out the user by calling the store's signOut function if available\n *\n * @returns {void}\n */\n signOut: () => {\n const signOutFn = useAuthStore.getState().signOut;\n if (typeof signOutFn === 'function') signOutFn();\n },\n };\n}\n"],"mappings":";AAkCO,SAAS,yBAOd,cAAqC;AACrC,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAML,WAAW,YAA8B;AACvC,YAAM,EAAE,aAAa,OAAO,IAAI,aAAa,SAAS;AACtD,aAAO,QAAQ,eAAe,MAAM;AAAA,IACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,SAAS,MAAM,aAAa,SAAS,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMvC,gBAAgB,MAAM,aAAa,SAAS,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAM9C,WAAW,MAAM,aAAa,SAAS,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMzC,SAAS,MAAM;AACb,YAAM,YAAY,aAAa,SAAS,EAAE;AAC1C,UAAI,OAAO,cAAc,WAAY,WAAU;AAAA,IACjD;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -30,6 +30,8 @@ export { default as Menu, MenuContent, MenuItem, MenuOverflow } from './Menu/ind
|
|
|
30
30
|
export { CardActivitiesResults, CardPerformance, CardProgress, CardQuestions, CardResults, CardSimulado, CardStatus, CardTopic } from './Card/index.mjs';
|
|
31
31
|
export { Skeleton, SkeletonCard, SkeletonCircle, SkeletonList, SkeletonRectangle, SkeletonRounded, SkeletonTable, SkeletonText } from './Skeleton/index.mjs';
|
|
32
32
|
export { AuthProvider, ProtectedRoute, PublicRoute, useAuth, useAuthGuard, useRouteAuth, withAuth } from './Auth/index.mjs';
|
|
33
|
+
export { createZustandAuthAdapter } from './Auth/zustandAuthAdapter/index.mjs';
|
|
34
|
+
export { useUrlAuthentication } from './Auth/useUrlAuthentication/index.mjs';
|
|
33
35
|
import 'react/jsx-runtime';
|
|
34
36
|
import 'react';
|
|
35
37
|
import 'zustand';
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export { default as Menu, MenuContent, MenuItem, MenuOverflow } from './Menu/ind
|
|
|
30
30
|
export { CardActivitiesResults, CardPerformance, CardProgress, CardQuestions, CardResults, CardSimulado, CardStatus, CardTopic } from './Card/index.js';
|
|
31
31
|
export { Skeleton, SkeletonCard, SkeletonCircle, SkeletonList, SkeletonRectangle, SkeletonRounded, SkeletonTable, SkeletonText } from './Skeleton/index.js';
|
|
32
32
|
export { AuthProvider, ProtectedRoute, PublicRoute, useAuth, useAuthGuard, useRouteAuth, withAuth } from './Auth/index.js';
|
|
33
|
+
export { createZustandAuthAdapter } from './Auth/zustandAuthAdapter/index.js';
|
|
34
|
+
export { useUrlAuthentication } from './Auth/useUrlAuthentication/index.js';
|
|
33
35
|
import 'react/jsx-runtime';
|
|
34
36
|
import 'react';
|
|
35
37
|
import 'zustand';
|
package/dist/index.js
CHANGED
|
@@ -85,10 +85,12 @@ __export(src_exports, {
|
|
|
85
85
|
TextArea: () => TextArea_default,
|
|
86
86
|
Toast: () => Toast_default,
|
|
87
87
|
Toaster: () => Toaster_default,
|
|
88
|
+
createZustandAuthAdapter: () => createZustandAuthAdapter,
|
|
88
89
|
useAuth: () => useAuth,
|
|
89
90
|
useAuthGuard: () => useAuthGuard,
|
|
90
91
|
useRouteAuth: () => useRouteAuth,
|
|
91
92
|
useToastStore: () => ToastStore_default,
|
|
93
|
+
useUrlAuthentication: () => useUrlAuthentication,
|
|
92
94
|
withAuth: () => withAuth
|
|
93
95
|
});
|
|
94
96
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -5872,6 +5874,14 @@ var ProtectedRoute = ({
|
|
|
5872
5874
|
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_jsx_runtime31.Fragment, { children: loadingComponent || defaultLoadingComponent });
|
|
5873
5875
|
}
|
|
5874
5876
|
if (!isAuthenticated) {
|
|
5877
|
+
if (typeof window !== "undefined") {
|
|
5878
|
+
const rootDomain = getRootDomain();
|
|
5879
|
+
const currentLocation = `${window.location.protocol}//${window.location.hostname}${window.location.port ? ":" + window.location.port : ""}`;
|
|
5880
|
+
if (rootDomain !== currentLocation) {
|
|
5881
|
+
window.location.href = rootDomain;
|
|
5882
|
+
return null;
|
|
5883
|
+
}
|
|
5884
|
+
}
|
|
5875
5885
|
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_react_router_dom.Navigate, { to: redirectTo, replace: true });
|
|
5876
5886
|
}
|
|
5877
5887
|
if (additionalCheck && !additionalCheck({ isAuthenticated, isLoading, ...authState })) {
|
|
@@ -5917,6 +5927,127 @@ var useRouteAuth = (fallbackPath = "/") => {
|
|
|
5917
5927
|
redirectToLogin
|
|
5918
5928
|
};
|
|
5919
5929
|
};
|
|
5930
|
+
var getRootDomain = () => {
|
|
5931
|
+
const { hostname, protocol, port } = window.location;
|
|
5932
|
+
const portStr = port ? ":" + port : "";
|
|
5933
|
+
if (hostname === "localhost") {
|
|
5934
|
+
return `${protocol}//${hostname}${portStr}`;
|
|
5935
|
+
}
|
|
5936
|
+
const parts = hostname.split(".");
|
|
5937
|
+
if (parts.length > 2) {
|
|
5938
|
+
const base = parts.slice(-2).join(".");
|
|
5939
|
+
return `${protocol}//${base}${portStr}`;
|
|
5940
|
+
}
|
|
5941
|
+
return `${protocol}//${hostname}${portStr}`;
|
|
5942
|
+
};
|
|
5943
|
+
|
|
5944
|
+
// src/components/Auth/zustandAuthAdapter.ts
|
|
5945
|
+
function createZustandAuthAdapter(useAuthStore) {
|
|
5946
|
+
return {
|
|
5947
|
+
/**
|
|
5948
|
+
* Check if the user is authenticated based on sessionInfo and tokens
|
|
5949
|
+
*
|
|
5950
|
+
* @returns {Promise<boolean>} Promise that resolves to authentication status
|
|
5951
|
+
*/
|
|
5952
|
+
checkAuth: async () => {
|
|
5953
|
+
const { sessionInfo, tokens } = useAuthStore.getState();
|
|
5954
|
+
return Boolean(sessionInfo && tokens);
|
|
5955
|
+
},
|
|
5956
|
+
/**
|
|
5957
|
+
* Get the current user from the store
|
|
5958
|
+
*
|
|
5959
|
+
* @returns {unknown} Current user data from the store
|
|
5960
|
+
*/
|
|
5961
|
+
getUser: () => useAuthStore.getState().user,
|
|
5962
|
+
/**
|
|
5963
|
+
* Get the current session information from the store
|
|
5964
|
+
*
|
|
5965
|
+
* @returns {unknown} Current session info from the store
|
|
5966
|
+
*/
|
|
5967
|
+
getSessionInfo: () => useAuthStore.getState().sessionInfo,
|
|
5968
|
+
/**
|
|
5969
|
+
* Get the current authentication tokens from the store
|
|
5970
|
+
*
|
|
5971
|
+
* @returns {unknown} Current tokens from the store
|
|
5972
|
+
*/
|
|
5973
|
+
getTokens: () => useAuthStore.getState().tokens,
|
|
5974
|
+
/**
|
|
5975
|
+
* Sign out the user by calling the store's signOut function if available
|
|
5976
|
+
*
|
|
5977
|
+
* @returns {void}
|
|
5978
|
+
*/
|
|
5979
|
+
signOut: () => {
|
|
5980
|
+
const signOutFn = useAuthStore.getState().signOut;
|
|
5981
|
+
if (typeof signOutFn === "function") signOutFn();
|
|
5982
|
+
}
|
|
5983
|
+
};
|
|
5984
|
+
}
|
|
5985
|
+
|
|
5986
|
+
// src/components/Auth/useUrlAuthentication.ts
|
|
5987
|
+
var import_react20 = require("react");
|
|
5988
|
+
var import_react_router_dom2 = require("react-router-dom");
|
|
5989
|
+
var getAuthParams = (location, extractParams) => {
|
|
5990
|
+
const searchParams = new URLSearchParams(location.search);
|
|
5991
|
+
return extractParams ? extractParams(searchParams) : {
|
|
5992
|
+
sessionId: searchParams.get("sessionId"),
|
|
5993
|
+
token: searchParams.get("token"),
|
|
5994
|
+
refreshToken: searchParams.get("refreshToken")
|
|
5995
|
+
};
|
|
5996
|
+
};
|
|
5997
|
+
var hasValidAuthParams = (authParams) => {
|
|
5998
|
+
return !!(authParams?.sessionId && authParams?.token && authParams?.refreshToken);
|
|
5999
|
+
};
|
|
6000
|
+
var hasValidProfileData = (data) => {
|
|
6001
|
+
return data !== null && typeof data === "object" && data !== void 0;
|
|
6002
|
+
};
|
|
6003
|
+
var handleProfileSelection = (responseData, setSelectedProfile) => {
|
|
6004
|
+
if (!setSelectedProfile) return;
|
|
6005
|
+
if (!hasValidProfileData(responseData)) return;
|
|
6006
|
+
const profileId = responseData.profileId;
|
|
6007
|
+
const isValidProfileId = profileId !== null && profileId !== void 0;
|
|
6008
|
+
if (isValidProfileId) {
|
|
6009
|
+
setSelectedProfile({
|
|
6010
|
+
id: profileId
|
|
6011
|
+
});
|
|
6012
|
+
}
|
|
6013
|
+
};
|
|
6014
|
+
function useUrlAuthentication(options) {
|
|
6015
|
+
const location = (0, import_react_router_dom2.useLocation)();
|
|
6016
|
+
(0, import_react20.useEffect)(() => {
|
|
6017
|
+
const handleAuthentication = async () => {
|
|
6018
|
+
const authParams = getAuthParams(location, options.extractParams);
|
|
6019
|
+
if (!hasValidAuthParams(authParams)) {
|
|
6020
|
+
return;
|
|
6021
|
+
}
|
|
6022
|
+
try {
|
|
6023
|
+
options.setTokens({
|
|
6024
|
+
token: authParams.token,
|
|
6025
|
+
refreshToken: authParams.refreshToken
|
|
6026
|
+
});
|
|
6027
|
+
const response = await options.api.get(options.endpoint, {
|
|
6028
|
+
headers: {
|
|
6029
|
+
Authorization: `Bearer ${authParams.token}`
|
|
6030
|
+
}
|
|
6031
|
+
});
|
|
6032
|
+
options.setSessionInfo(response.data.data);
|
|
6033
|
+
handleProfileSelection(response.data.data, options.setSelectedProfile);
|
|
6034
|
+
options.clearParamsFromURL?.();
|
|
6035
|
+
} catch (error) {
|
|
6036
|
+
console.error("Erro ao obter informa\xE7\xF5es da sess\xE3o:", error);
|
|
6037
|
+
}
|
|
6038
|
+
};
|
|
6039
|
+
handleAuthentication();
|
|
6040
|
+
}, [
|
|
6041
|
+
location.search,
|
|
6042
|
+
options.setSessionInfo,
|
|
6043
|
+
options.setSelectedProfile,
|
|
6044
|
+
options.setTokens,
|
|
6045
|
+
options.api,
|
|
6046
|
+
options.endpoint,
|
|
6047
|
+
options.extractParams,
|
|
6048
|
+
options.clearParamsFromURL
|
|
6049
|
+
]);
|
|
6050
|
+
}
|
|
5920
6051
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5921
6052
|
0 && (module.exports = {
|
|
5922
6053
|
Alert,
|
|
@@ -5984,10 +6115,12 @@ var useRouteAuth = (fallbackPath = "/") => {
|
|
|
5984
6115
|
TextArea,
|
|
5985
6116
|
Toast,
|
|
5986
6117
|
Toaster,
|
|
6118
|
+
createZustandAuthAdapter,
|
|
5987
6119
|
useAuth,
|
|
5988
6120
|
useAuthGuard,
|
|
5989
6121
|
useRouteAuth,
|
|
5990
6122
|
useToastStore,
|
|
6123
|
+
useUrlAuthentication,
|
|
5991
6124
|
withAuth
|
|
5992
6125
|
});
|
|
5993
6126
|
//# sourceMappingURL=index.js.map
|