fix: get the APIClient instance from the app instance

This commit is contained in:
chenos 2024-06-19 13:20:15 +08:00
parent 0e778e7e47
commit 2d2f1c8cc8

View File

@ -7,21 +7,21 @@
* For more information, please refer to: https://www.nocobase.com/agreement. * For more information, please refer to: https://www.nocobase.com/agreement.
*/ */
import { useAPIClient } from '@nocobase/client'; import { useApp } from '@nocobase/client';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { useLocation } from 'react-router-dom'; import { useLocation } from 'react-router-dom';
export const AuthProvider: React.FC = (props) => { export const AuthProvider: React.FC = (props) => {
const location = useLocation(); const location = useLocation();
const api = useAPIClient(); const app = useApp();
useEffect(() => { useEffect(() => {
const params = new URLSearchParams(location.search); const params = new URLSearchParams(location.search);
const authenticator = params.get('authenticator'); const authenticator = params.get('authenticator');
const token = params.get('token'); const token = params.get('token');
if (token) { if (token) {
api.auth.setToken(token); app.apiClient.auth.setToken(token);
api.auth.setAuthenticator(authenticator); app.apiClient.auth.setAuthenticator(authenticator);
} }
}); });
return <>{props.children}</>; return <>{props.children}</>;