Skip to content
This repository has been archived by the owner on Oct 8, 2023. It is now read-only.

Commit

Permalink
upgrade and remove un required isAccessAllowed code (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
borisno2 authored Dec 4, 2022
1 parent ea0a634 commit b9dbb77
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 164 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-dots-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@opensaas/keystone-nextjs-auth': patch
---

Resolve error when `isAccessAllowed` is not defined
5 changes: 5 additions & 0 deletions .changeset/wicked-months-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@opensaas/keystone-nextjs-auth': minor
---

Upgrade to keystone `3.1.0`
2 changes: 1 addition & 1 deletion backend/keystone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default auth.withAuth(
useMigrations: true,
},
ui: {
isAccessAllowed: (context: KeystoneContext) => !!context.session?.data,
isAccessAllowed: (context: KeystoneContext) => !!context.session,
publicPages: ['/admin/auth/signin', '/admin/auth/error'],
getAdditionalFiles: [
async () => [
Expand Down
8 changes: 4 additions & 4 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"start": "keystone prisma migrate deploy && keystone start"
},
"dependencies": {
"@keystone-6/core": "3.0.0",
"@keystone-6/fields-document": "4.1.2",
"@keystone-ui/button": "7.0.1",
"@keystone-ui/core": "5.0.1",
"@keystone-6/core": "3.1.3",
"@keystone-6/fields-document": "5.0.2",
"@keystone-ui/button": "7.0.2",
"@keystone-ui/core": "5.0.2",
"@opensaas/keystone-nextjs-auth": "^25.0.0",
"@types/ejs": "^3.1.1",
"dotenv": "^16.0.2",
Expand Down
15 changes: 14 additions & 1 deletion backend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,10 @@ type KeystoneAdminUIListMeta {
pageSize: Int!
labelField: String!
fields: [KeystoneAdminUIFieldMeta!]!
groups: [KeystoneAdminUIFieldGroupMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
isSingleton: Boolean!
}

type KeystoneAdminUIFieldMeta {
Expand Down Expand Up @@ -303,6 +304,7 @@ enum KeystoneAdminUIFieldMetaListViewFieldMode {

type KeystoneAdminUIFieldMetaItemView {
fieldMode: KeystoneAdminUIFieldMetaItemViewFieldMode
fieldPosition: KeystoneAdminUIFieldMetaItemViewFieldPosition
}

enum KeystoneAdminUIFieldMetaItemViewFieldMode {
Expand All @@ -311,6 +313,17 @@ enum KeystoneAdminUIFieldMetaItemViewFieldMode {
hidden
}

enum KeystoneAdminUIFieldMetaItemViewFieldPosition {
form
sidebar
}

type KeystoneAdminUIFieldGroupMeta {
label: String!
description: String
fields: [KeystoneAdminUIFieldMeta!]!
}

type KeystoneAdminUISort {
field: String!
direction: KeystoneAdminUISortDirection!
Expand Down
4 changes: 2 additions & 2 deletions packages/keystone-nextjs-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"next-auth": "^4.16.4"
},
"devDependencies": {
"@keystone-6/core": "3.0.0",
"@keystone-6/core": "3.1.3",
"react": "^18.2.0"
},
"peerDependencies": {
"@keystone-6/core": "3.0.0",
"@keystone-6/core": "3.1.3",
"react": "^18.2.0"
},
"publishConfig": {
Expand Down
24 changes: 0 additions & 24 deletions packages/keystone-nextjs-auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
AdminFileToWrite,
BaseListTypeInfo,
KeystoneConfig,
KeystoneContext,
AdminUIConfig,
BaseKeystoneTypeInfo,
SessionStrategy,
Expand Down Expand Up @@ -284,29 +283,6 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
getAdditionalFiles: [...(keystoneConfig.ui?.getAdditionalFiles || []), getAdditionalFiles],
pageMiddleware: async args =>
(await pageMiddleware(args)) ?? keystoneConfig?.ui?.pageMiddleware?.(args),
isAccessAllowed: async (context: KeystoneContext) => {
const { req } = context;
const pathname = url.parse(req?.url!).pathname!;

// Allow nextjs scripts and static files to be accessed without auth
if (pathname.includes('/_next/')) {
return true;
}

// Allow keystone to access /api/__keystone_api_build for hot reloading
if (
process.env.NODE_ENV !== 'production' &&
context.req?.url !== undefined &&
new URL(context.req.url, 'http://example.com').pathname ===
`${customPath}/api/__keystone_api_build`
) {
return true;
}

return keystoneConfig.ui?.isAccessAllowed
? keystoneConfig.ui.isAccessAllowed(context)
: context.session !== undefined;
},
};
}

Expand Down
Loading

0 comments on commit b9dbb77

Please sign in to comment.