Skip to content

Commit

Permalink
Remove legacy keystone.createAuthStrategy() (#5220)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Mar 25, 2021
1 parent 7dd0f00 commit 7ae452a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 352 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-peas-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone-legacy': major
---

Removed the legacy `keystone.createAuthStrategy()` method.
28 changes: 8 additions & 20 deletions packages/keystone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,14 @@ _**Default:**_ `['public']`

## Methods

| Method | Description |
| -------------------- | ------------------------------------------------------------------- |
| `connect` | Manually connect to Adapter. |
| `createAuthStrategy` | Creates a new authentication middleware instance. |
| `createList` | Add a list to the `Keystone` schema. |
| `disconnect` | Disconnect from the adapter. |
| `prepare` | Manually prepare `Keystone` middlewares. |
| `createContext` | Create a `context` object that can be used with `executeGraphQL()`. |
| `executeGraphQL` | Execute a server-side GraphQL operation within the given context. |
| Method | Description |
| ---------------- | ------------------------------------------------------------------- |
| `connect` | Manually connect to Adapter. |
| `createList` | Add a list to the `Keystone` schema. |
| `disconnect` | Disconnect from the adapter. |
| `prepare` | Manually prepare `Keystone` middlewares. |
| `createContext` | Create a `context` object that can be used with `executeGraphQL()`. |
| `executeGraphQL` | Execute a server-side GraphQL operation within the given context. |

<!--
## Super secret methods
Expand All @@ -116,17 +115,6 @@ keystone.connect();

> **Note:** `keystone.connect()` is only required for custom servers. Most example projects use the `keystone start` command to start a server and automatically connect.
### `createAuthStrategy(config)`

Creates a new authentication middleware instance. See:

- [Authentication guide](https://www.keystonejs.com/guides/authentication)
- [Authentication API docs](https://www.keystonejs.com/api/authentication)

```javascript allowCopy=false showLanguage=false
const authStrategy = keystone.createAuthStrategy({...});
```

### `createList(listKey, config)`

Registers a new list with Keystone and returns a `Keystone` list object. See:
Expand Down
24 changes: 2 additions & 22 deletions packages/keystone/lib/Keystone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
const { SessionManager } = require('@keystone-next/session-legacy');

const { List } = require('../ListTypes');
const { ListAuthProvider, ListCRUDProvider } = require('../providers');
const { ListCRUDProvider } = require('../providers');
const { formatError } = require('./format-error');

// composePlugins([f, g, h])(o, e) = h(g(f(o, e), e), e)
Expand Down Expand Up @@ -189,26 +189,6 @@ module.exports = class Keystone {
return execute(schema, query, null, context, variables);
}

createAuthStrategy(options) {
const { type: StrategyType, list: listKey, config, hooks } = composePlugins(
options.plugins || []
)(options, { keystone: this });
const { authType } = StrategyType;
if (!this.auth[listKey]) {
this.auth[listKey] = {};
}
const strategy = new StrategyType(this, listKey, config);
strategy.authType = authType;
this.auth[listKey][authType] = strategy;
if (!this.lists[listKey]) {
throw new Error(`List "${listKey}" does not exist.`);
}
this._providers.push(
new ListAuthProvider({ list: this.lists[listKey], authStrategy: strategy, hooks })
);
return strategy;
}

createList(key, config, { isAuxList = false } = {}) {
const { getListByKey, adapter } = this;
const isReservedName = !isAuxList && key[0] === '_';
Expand Down Expand Up @@ -519,7 +499,7 @@ module.exports = class Keystone {
this.createApolloServer({ schemaName: 'internal' });
const middlewares = await this._prepareMiddlewares({ dev, apps, distDir, pinoOptions, cors });
// These function can't be called after prepare(), so make them throw an error from now on.
['createList', 'createAuthStrategy'].forEach(f => {
['createList'].forEach(f => {
this[f] = () => {
throw new Error(`keystone.${f} must be called before keystone.prepare()`);
};
Expand Down
3 changes: 1 addition & 2 deletions packages/keystone/lib/providers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { ListAuthProvider } = require('./listAuth');
const { ListCRUDProvider } = require('./listCRUD');

// The GraphQL Provider Framework expects to see classes with the following API:
Expand Down Expand Up @@ -33,4 +32,4 @@ const { ListCRUDProvider } = require('./listCRUD');
// }
// }

module.exports = { ListAuthProvider, ListCRUDProvider };
module.exports = { ListCRUDProvider };
Loading

1 comment on commit 7ae452a

@vercel
Copy link

@vercel vercel bot commented on 7ae452a Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.