mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
feat: add ctx.auth
This commit is contained in:
parent
e43191df17
commit
d6d9e213dc
@ -10,7 +10,7 @@
|
||||
import React, { createContext, useContext, useMemo } from 'react';
|
||||
import { useACLRoleContext } from '../acl';
|
||||
import { ReturnTypeOfUseRequest, useAPIClient, useRequest } from '../api-client';
|
||||
import { useAppSpin } from '../application';
|
||||
import { useApp, useAppSpin } from '../application';
|
||||
import { useCompile } from '../schema-component';
|
||||
|
||||
export const CurrentUserContext = createContext<ReturnTypeOfUseRequest>(null);
|
||||
@ -44,6 +44,7 @@ export const useCurrentRoles = () => {
|
||||
|
||||
export const CurrentUserProvider = (props) => {
|
||||
const api = useAPIClient();
|
||||
const app = useApp();
|
||||
const result = useRequest<any>(() =>
|
||||
api
|
||||
.request({
|
||||
@ -51,7 +52,12 @@ export const CurrentUserProvider = (props) => {
|
||||
skipNotify: true,
|
||||
skipAuth: true,
|
||||
})
|
||||
.then((res) => res?.data),
|
||||
.then((res) => {
|
||||
app.flowEngine.setContext({
|
||||
user: res?.data?.data,
|
||||
});
|
||||
return res?.data;
|
||||
}),
|
||||
);
|
||||
|
||||
const { render } = useAppSpin();
|
||||
|
@ -7,7 +7,7 @@
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import { BlockModel } from '@nocobase/client';
|
||||
import { APIClient, BlockModel } from '@nocobase/client';
|
||||
import {
|
||||
APIResource,
|
||||
BaseRecordResource,
|
||||
@ -263,6 +263,7 @@ ctx.element.innerHTML = \`
|
||||
const flowEngine = flowContext.globals.flowEngine as FlowEngine;
|
||||
|
||||
const request = flowContext.globals.api.request.bind(flowContext.globals.api);
|
||||
const api = flowContext.app.apiClient as APIClient;
|
||||
|
||||
// Create a safe execution context for the code (as async function)
|
||||
// Wrap user code in an async function
|
||||
@ -300,6 +301,12 @@ ctx.element.innerHTML = \`
|
||||
React,
|
||||
ReactDOM,
|
||||
flowEngine,
|
||||
auth: {
|
||||
role: api.auth.role,
|
||||
locale: api.auth.locale,
|
||||
token: api.auth.token,
|
||||
user: flowContext.globals.user,
|
||||
},
|
||||
Components: {
|
||||
antd,
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user