Merge branch 'master' of github.com:keen-studio/payload

This commit is contained in:
James
2020-10-26 16:56:31 -04:00
20 changed files with 38 additions and 36 deletions

View File

@@ -4,7 +4,7 @@ import {
} from 'react-router-dom';
import { useConfig } from './providers/Config';
import List from './views/collections/List';
import { useAuthentication } from './providers/Authentication';
import { useAuth } from './providers/Authentication';
import DefaultTemplate from './templates/Default';
import { requests } from '../api';
import Loading from './elements/Loading';
@@ -25,7 +25,7 @@ const Account = lazy(() => import('./views/Account'));
const Routes = () => {
const history = useHistory();
const [initialized, setInitialized] = useState(null);
const { user, permissions, permissions: { canAccessAdmin } } = useAuthentication();
const { user, permissions, permissions: { canAccessAdmin } } = useAuth();
const {
admin: { user: userSlug }, routes, collections, globals,

View File

@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react';
import { NavLink, Link, useHistory } from 'react-router-dom';
import { useConfig } from '../../providers/Config';
import { useAuthentication } from '../../providers/Authentication';
import { useAuth } from '../../providers/Authentication';
import RenderCustomComponent from '../../utilities/RenderCustomComponent';
import Chevron from '../../icons/Chevron';
import LogOut from '../../icons/LogOut';
@@ -16,7 +16,7 @@ import './index.scss';
const baseClass = 'nav';
const DefaultNav = () => {
const { permissions } = useAuthentication();
const { permissions } = useAuth();
const [menuActive, setMenuActive] = useState(false);
const history = useHistory();
const {

View File

@@ -1,13 +1,13 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useForm } from '../../forms/Form/context';
import { useAuthentication } from '../../providers/Authentication';
import { useAuth } from '../../providers/Authentication';
import Button from '../Button';
const baseClass = 'preview-btn';
const PreviewButton = ({ generatePreviewURL }) => {
const { token } = useAuthentication();
const { token } = useAuth();
const { getFields } = useForm();
const fields = getFields();

View File

@@ -8,7 +8,7 @@ import { useLocale } from '../../utilities/Locale';
import { useStatusList } from '../../elements/Status';
import { requests } from '../../../api';
import useThrottledEffect from '../../../hooks/useThrottledEffect';
import { useAuthentication } from '../../providers/Authentication';
import { useAuth } from '../../providers/Authentication';
import fieldReducer from './fieldReducer';
import initContextState from './initContextState';
import reduceFieldsToValues from './reduceFieldsToValues';
@@ -46,7 +46,7 @@ const Form = (props) => {
const history = useHistory();
const locale = useLocale();
const { replaceStatus, addStatus, clearStatus } = useStatusList();
const { refreshCookie } = useAuthentication();
const { refreshCookie } = useAuth();
const [modified, setModified] = useState(false);
const [processing, setProcessing] = useState(false);

View File

@@ -4,7 +4,7 @@ import Relationship from '../../../../../Relationship';
import Number from '../../../../../Number';
import Select from '../../../../../Select';
import { useConfig } from '../../../../../../../providers/Config';
import { useAuthentication } from '../../../../../../../providers/Authentication';
import { useAuth } from '../../../../../../../providers/Authentication';
const createOptions = (collections, permissions) => collections.reduce((options, collection) => {
if (permissions[collection.slug]?.read?.permission && collection?.admin?.enableRichTextRelationship) {
@@ -22,7 +22,7 @@ const createOptions = (collections, permissions) => collections.reduce((options,
const RelationshipFields = () => {
const { collections, maxDepth } = useConfig();
const { permissions } = useAuthentication();
const { permissions } = useAuth();
const [options, setOptions] = useState(() => createOptions(collections, permissions));

View File

@@ -3,7 +3,7 @@ import NavigationPrompt from 'react-router-navigation-prompt';
import { useFormModified } from '../../forms/Form/context';
import MinimalTemplate from '../../templates/Minimal';
import Button from '../../elements/Button';
import { useAuthentication } from '../../providers/Authentication';
import { useAuth } from '../../providers/Authentication';
import './index.scss';
@@ -11,7 +11,7 @@ const modalSlug = 'leave-without-saving';
const LeaveWithoutSaving = () => {
const modified = useFormModified();
const { user } = useAuthentication();
const { user } = useAuth();
return (
<NavigationPrompt when={modified && user}>

View File

@@ -173,9 +173,9 @@ AuthenticationProvider.propTypes = {
]).isRequired,
};
const useAuthentication = () => useContext(Context);
const useAuth = () => useContext(Context);
export {
AuthenticationProvider,
useAuthentication,
useAuth,
};

View File

@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import { useConfig } from '../../providers/Config';
import { useStepNav } from '../../elements/StepNav';
import { useAuthentication } from '../../providers/Authentication';
import { useAuth } from '../../providers/Authentication';
import usePayloadAPI from '../../../hooks/usePayloadAPI';
import DefaultAccount from './Default';
import buildStateFromSchema from '../../forms/Form/buildStateFromSchema';
@@ -12,7 +12,7 @@ import { NegativeFieldGutterProvider } from '../../forms/FieldTypeGutter/context
const AccountView = () => {
const { state: locationState } = useLocation();
const { setStepNav } = useStepNav();
const { user, permissions } = useAuthentication();
const { user, permissions } = useAuth();
const [initialState, setInitialState] = useState({});
const {
serverURL,

View File

@@ -7,7 +7,7 @@ import Form from '../../forms/Form';
import RenderFields from '../../forms/RenderFields';
import fieldTypes from '../../forms/field-types';
import FormSubmit from '../../forms/Submit';
import { useAuthentication } from '../../providers/Authentication';
import { useAuth } from '../../providers/Authentication';
import { NegativeFieldGutterProvider } from '../../forms/FieldTypeGutter/context';
import './index.scss';
@@ -16,7 +16,7 @@ const baseClass = 'create-first-user';
const CreateFirstUser = (props) => {
const { setInitialized } = props;
const { setToken } = useAuthentication();
const { setToken } = useAuth();
const {
admin: { user: userSlug }, collections, serverURL, routes: { admin, api },
} = useConfig();

View File

@@ -1,12 +1,12 @@
import React, { useState, useEffect } from 'react';
import { useConfig } from '../../providers/Config';
import { useAuthentication } from '../../providers/Authentication';
import { useAuth } from '../../providers/Authentication';
import { useStepNav } from '../../elements/StepNav';
import RenderCustomComponent from '../../utilities/RenderCustomComponent';
import DefaultDashboard from './Default';
const Dashboard = () => {
const { permissions } = useAuthentication();
const { permissions } = useAuth();
const { setStepNav } = useStepNav();
const [filteredGlobals, setFilteredGlobals] = useState([]);

View File

@@ -8,7 +8,7 @@ import Email from '../../forms/field-types/Email';
import FormSubmit from '../../forms/Submit';
import Button from '../../elements/Button';
import Meta from '../../utilities/Meta';
import { useAuthentication } from '../../providers/Authentication';
import { useAuth } from '../../providers/Authentication';
import './index.scss';
@@ -17,7 +17,7 @@ const baseClass = 'forgot-password';
const ForgotPassword = () => {
const { addStatus } = useStatusList();
const [hasSubmitted, setHasSubmitted] = useState(false);
const { user } = useAuthentication();
const { user } = useAuth();
const {
admin: { user: userSlug },
serverURL,

View File

@@ -4,7 +4,7 @@ import { useHistory, useLocation } from 'react-router-dom';
import { useConfig } from '../../providers/Config';
import { useStepNav } from '../../elements/StepNav';
import usePayloadAPI from '../../../hooks/usePayloadAPI';
import { useAuthentication } from '../../providers/Authentication';
import { useAuth } from '../../providers/Authentication';
import { useLocale } from '../../utilities/Locale';
import RenderCustomComponent from '../../utilities/RenderCustomComponent';
@@ -17,7 +17,7 @@ const GlobalView = (props) => {
const history = useHistory();
const locale = useLocale();
const { setStepNav } = useStepNav();
const { permissions } = useAuthentication();
const { permissions } = useAuth();
const [initialState, setInitialState] = useState({});
const {

View File

@@ -9,7 +9,7 @@ import Password from '../../forms/field-types/Password';
import FormSubmit from '../../forms/Submit';
import Button from '../../elements/Button';
import Meta from '../../utilities/Meta';
import { useAuthentication } from '../../providers/Authentication';
import { useAuth } from '../../providers/Authentication';
import './index.scss';
@@ -17,7 +17,7 @@ const baseClass = 'login';
const Login = () => {
const history = useHistory();
const { user, setToken } = useAuthentication();
const { user, setToken } = useAuth();
const { admin: { user: userSlug }, serverURL, routes: { admin, api } } = useConfig();
const onSuccess = (data) => {

View File

@@ -1,7 +1,7 @@
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import { useConfig } from '../../providers/Config';
import { useAuthentication } from '../../providers/Authentication';
import { useAuth } from '../../providers/Authentication';
import Minimal from '../../templates/Minimal';
import Button from '../../elements/Button';
import Meta from '../../utilities/Meta';
@@ -13,7 +13,7 @@ const baseClass = 'logout';
const Logout = (props) => {
const { inactivity } = props;
const { logOut } = useAuthentication();
const { logOut } = useAuth();
const { routes: { admin } } = useConfig();
useEffect(() => {

View File

@@ -8,7 +8,7 @@ import ConfirmPassword from '../../forms/field-types/ConfirmPassword';
import FormSubmit from '../../forms/Submit';
import Button from '../../elements/Button';
import Meta from '../../utilities/Meta';
import { useAuthentication } from '../../providers/Authentication';
import { useAuth } from '../../providers/Authentication';
import './index.scss';
import HiddenInput from '../../forms/field-types/HiddenInput';
@@ -19,7 +19,7 @@ const ResetPassword = () => {
const { admin: { user: userSlug }, serverURL, routes: { admin, api } } = useConfig();
const { token } = useParams();
const history = useHistory();
const { user, setToken } = useAuthentication();
const { user, setToken } = useAuth();
const onSuccess = (data) => {
if (data.token) {

View File

@@ -7,7 +7,7 @@ import Button from '../../elements/Button';
import Meta from '../../utilities/Meta';
import { useConfig } from '../../providers/Config';
import { useAuthentication } from '../../providers/Authentication';
import { useAuth } from '../../providers/Authentication';
import Login from '../Login';
import './index.scss';
@@ -16,7 +16,7 @@ const baseClass = 'verify';
const Verify = ({ collection }) => {
const { slug: collectionSlug } = collection;
const { user } = useAuthentication();
const { user } = useAuth();
const { token } = useParams();
const { serverURL, routes: { admin: adminRoute }, admin: { user: adminUser } } = useConfig();

View File

@@ -4,7 +4,7 @@ import { Redirect, useRouteMatch, useHistory, useLocation } from 'react-router-d
import { useConfig } from '../../../providers/Config';
import { useStepNav } from '../../../elements/StepNav';
import usePayloadAPI from '../../../../hooks/usePayloadAPI';
import { useAuthentication } from '../../../providers/Authentication';
import { useAuth } from '../../../providers/Authentication';
import RenderCustomComponent from '../../../utilities/RenderCustomComponent';
import DefaultEdit from './Default';
@@ -36,7 +36,7 @@ const EditView = (props) => {
const history = useHistory();
const { setStepNav } = useStepNav();
const [initialState, setInitialState] = useState({});
const { permissions } = useAuthentication();
const { permissions } = useAuth();
const onSave = (json) => {
history.push(`${admin}/collections/${collection.slug}/${json?.doc?.id}`, {

View File

@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import queryString from 'qs';
import { useLocation } from 'react-router-dom';
import { useConfig } from '../../../providers/Config';
import { useAuthentication } from '../../../providers/Authentication';
import { useAuth } from '../../../providers/Authentication';
import usePayloadAPI from '../../../../hooks/usePayloadAPI';
import DefaultList from './Default';
import RenderCustomComponent from '../../../utilities/RenderCustomComponent';
@@ -28,7 +28,7 @@ const ListView = (props) => {
} = props;
const { serverURL, routes: { api, admin } } = useConfig();
const { permissions } = useAuthentication();
const { permissions } = useAuth();
const location = useLocation();
const { setStepNav } = useStepNav();

View File

@@ -101,6 +101,7 @@ class Payload {
// If not initializing locally, set up HTTP routing
if (!this.config.local) {
this.express = options.express;
if (this.config.rateLimit?.trustProxy) this.express.set('trust proxy', 1);
this.initAdmin();