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:
chenos 2025-02-25 19:59:46 +08:00 committed by GitHub
parent b6ee7ae2ad
commit 76e5e7c1c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 19 additions and 12 deletions

View File

@ -68,6 +68,9 @@ export abstract class Auth implements IAuth {
}
async skipCheck() {
if (this.ctx.skipAuthCheck === true) {
return true;
}
const token = this.ctx.getBearerToken();
if (!token && this.ctx.app.options.acl === false) {
return true;

View File

@ -7,10 +7,10 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { Collection, Model } from '@nocobase/database';
import { Cache } from '@nocobase/cache';
import { Collection, Model } from '@nocobase/database';
import jwt from 'jsonwebtoken';
import { Auth, AuthConfig, AuthErrorCode, AuthError } from '../auth';
import { Auth, AuthConfig, AuthError, AuthErrorCode } from '../auth';
import { JwtService } from './jwt-service';
import { ITokenControlService } from './token-control-service';

View File

@ -27,6 +27,8 @@ export type ResourceActionOptions<P = any> = {
action?: string;
params?: P;
url?: string;
skipNotify?: boolean | ((error: any) => boolean);
skipAuth?: boolean;
};
export type UseRequestService<P> = AxiosRequestConfig<P> | ResourceActionOptions<P> | FunctionService;

View File

@ -7,38 +7,38 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { css } from '@emotion/css';
import { useField } from '@formily/react';
import {
ACLCustomContext,
Action,
APIClient,
APIClientProvider,
AssociationField,
CollectionManager,
DataSource,
DataSourceApplicationProvider,
DataSourceManager,
DatePicker,
GlobalThemeProvider,
PoweredBy,
SchemaComponent,
SchemaComponentContext,
useAPIClient,
useApp,
useRequest,
ACLCustomContext,
VariablesProvider,
GlobalThemeProvider,
AssociationField,
Action,
DatePicker,
} 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 React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
import { isDesktop } from 'react-device-detect';
import { useParams } from 'react-router';
import { usePublicSubmitActionProps } from '../hooks';
import { UnEnabledFormPlaceholder, UnFoundFormPlaceholder } from './UnEnabledFormPlaceholder';
import { Button as MobileButton, Dialog as MobileDialog } from 'antd-mobile';
import { MobilePicker } from './components/MobilePicker';
import { MobileDateTimePicker } from './components/MobileDatePicker';
import { MobilePicker } from './components/MobilePicker';
class PublicDataSource extends DataSource {
async getDataSource() {
return {};
@ -158,6 +158,7 @@ function InternalPublicForm() {
const { error, data, loading, run } = useRequest<any>(
{
url: `publicForms:getMeta/${params.name}`,
skipAuth: true,
},
{
onSuccess(data) {

View File

@ -150,6 +150,7 @@ export class PluginPublicFormsServer extends Plugin {
if (actionName === 'publicSubmit') {
ctx.action.actionName = 'create';
}
ctx.skipAuthCheck = true;
} catch (error) {
ctx.throw(401, error.message);
}
@ -192,7 +193,7 @@ export class PluginPublicFormsServer extends Plugin {
});
this.app.dataSourceManager.afterAddDataSource((dataSource) => {
dataSource.resourceManager.use(this.parseToken, {
before: 'acl',
before: 'auth',
});
dataSource.acl.use(this.parseACL, {
before: 'core',