mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
fix: skip auth check in the public form (#6284)
* fix: skipAuthCheck * fix: before auth * fix: skip auth * feat: add skipAuth option to ResourceActionOptions * feat: add skipNotify option to ResourceActionOptions --------- Co-authored-by: sheldon guo <sheldon_66@163.com>
This commit is contained in:
parent
b6ee7ae2ad
commit
76e5e7c1c0
@ -68,6 +68,9 @@ export abstract class Auth implements IAuth {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async skipCheck() {
|
async skipCheck() {
|
||||||
|
if (this.ctx.skipAuthCheck === true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
const token = this.ctx.getBearerToken();
|
const token = this.ctx.getBearerToken();
|
||||||
if (!token && this.ctx.app.options.acl === false) {
|
if (!token && this.ctx.app.options.acl === false) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Collection, Model } from '@nocobase/database';
|
|
||||||
import { Cache } from '@nocobase/cache';
|
import { Cache } from '@nocobase/cache';
|
||||||
|
import { Collection, Model } from '@nocobase/database';
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import { Auth, AuthConfig, AuthErrorCode, AuthError } from '../auth';
|
import { Auth, AuthConfig, AuthError, AuthErrorCode } from '../auth';
|
||||||
import { JwtService } from './jwt-service';
|
import { JwtService } from './jwt-service';
|
||||||
import { ITokenControlService } from './token-control-service';
|
import { ITokenControlService } from './token-control-service';
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@ export type ResourceActionOptions<P = any> = {
|
|||||||
action?: string;
|
action?: string;
|
||||||
params?: P;
|
params?: P;
|
||||||
url?: string;
|
url?: string;
|
||||||
|
skipNotify?: boolean | ((error: any) => boolean);
|
||||||
|
skipAuth?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UseRequestService<P> = AxiosRequestConfig<P> | ResourceActionOptions<P> | FunctionService;
|
export type UseRequestService<P> = AxiosRequestConfig<P> | ResourceActionOptions<P> | FunctionService;
|
||||||
|
@ -7,38 +7,38 @@
|
|||||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { css } from '@emotion/css';
|
||||||
|
import { useField } from '@formily/react';
|
||||||
import {
|
import {
|
||||||
|
ACLCustomContext,
|
||||||
|
Action,
|
||||||
APIClient,
|
APIClient,
|
||||||
APIClientProvider,
|
APIClientProvider,
|
||||||
|
AssociationField,
|
||||||
CollectionManager,
|
CollectionManager,
|
||||||
DataSource,
|
DataSource,
|
||||||
DataSourceApplicationProvider,
|
DataSourceApplicationProvider,
|
||||||
DataSourceManager,
|
DataSourceManager,
|
||||||
|
DatePicker,
|
||||||
|
GlobalThemeProvider,
|
||||||
PoweredBy,
|
PoweredBy,
|
||||||
SchemaComponent,
|
SchemaComponent,
|
||||||
SchemaComponentContext,
|
SchemaComponentContext,
|
||||||
useAPIClient,
|
useAPIClient,
|
||||||
useApp,
|
useApp,
|
||||||
useRequest,
|
useRequest,
|
||||||
ACLCustomContext,
|
|
||||||
VariablesProvider,
|
VariablesProvider,
|
||||||
GlobalThemeProvider,
|
|
||||||
AssociationField,
|
|
||||||
Action,
|
|
||||||
DatePicker,
|
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
import { css } from '@emotion/css';
|
|
||||||
import { isDesktop } from 'react-device-detect';
|
|
||||||
import { useField } from '@formily/react';
|
|
||||||
import { Input, Modal, Spin } from 'antd';
|
import { Input, Modal, Spin } from 'antd';
|
||||||
import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
||||||
|
import { isDesktop } from 'react-device-detect';
|
||||||
import { useParams } from 'react-router';
|
import { useParams } from 'react-router';
|
||||||
import { usePublicSubmitActionProps } from '../hooks';
|
import { usePublicSubmitActionProps } from '../hooks';
|
||||||
import { UnEnabledFormPlaceholder, UnFoundFormPlaceholder } from './UnEnabledFormPlaceholder';
|
import { UnEnabledFormPlaceholder, UnFoundFormPlaceholder } from './UnEnabledFormPlaceholder';
|
||||||
|
|
||||||
import { Button as MobileButton, Dialog as MobileDialog } from 'antd-mobile';
|
import { Button as MobileButton, Dialog as MobileDialog } from 'antd-mobile';
|
||||||
import { MobilePicker } from './components/MobilePicker';
|
|
||||||
import { MobileDateTimePicker } from './components/MobileDatePicker';
|
import { MobileDateTimePicker } from './components/MobileDatePicker';
|
||||||
|
import { MobilePicker } from './components/MobilePicker';
|
||||||
class PublicDataSource extends DataSource {
|
class PublicDataSource extends DataSource {
|
||||||
async getDataSource() {
|
async getDataSource() {
|
||||||
return {};
|
return {};
|
||||||
@ -158,6 +158,7 @@ function InternalPublicForm() {
|
|||||||
const { error, data, loading, run } = useRequest<any>(
|
const { error, data, loading, run } = useRequest<any>(
|
||||||
{
|
{
|
||||||
url: `publicForms:getMeta/${params.name}`,
|
url: `publicForms:getMeta/${params.name}`,
|
||||||
|
skipAuth: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
onSuccess(data) {
|
onSuccess(data) {
|
||||||
|
@ -150,6 +150,7 @@ export class PluginPublicFormsServer extends Plugin {
|
|||||||
if (actionName === 'publicSubmit') {
|
if (actionName === 'publicSubmit') {
|
||||||
ctx.action.actionName = 'create';
|
ctx.action.actionName = 'create';
|
||||||
}
|
}
|
||||||
|
ctx.skipAuthCheck = true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ctx.throw(401, error.message);
|
ctx.throw(401, error.message);
|
||||||
}
|
}
|
||||||
@ -192,7 +193,7 @@ export class PluginPublicFormsServer extends Plugin {
|
|||||||
});
|
});
|
||||||
this.app.dataSourceManager.afterAddDataSource((dataSource) => {
|
this.app.dataSourceManager.afterAddDataSource((dataSource) => {
|
||||||
dataSource.resourceManager.use(this.parseToken, {
|
dataSource.resourceManager.use(this.parseToken, {
|
||||||
before: 'acl',
|
before: 'auth',
|
||||||
});
|
});
|
||||||
dataSource.acl.use(this.parseACL, {
|
dataSource.acl.use(this.parseACL, {
|
||||||
before: 'core',
|
before: 'core',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user