Skip to content

Commit 4b4f897

Browse files
committed
fix: Disable payload database session when local strategy is enabled (#49)
1 parent 774a094 commit 4b4f897

5 files changed

Lines changed: 8 additions & 6 deletions

File tree

examples/with-payload-local-strategy/src/collections/users.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const Users: CollectionConfig = {
1212
* @see https://payloadcms.com/docs/authentication/api-keys
1313
*/
1414
useAPIKey: true,
15-
useSessions: false, // TODO: Database sessions currently not working
1615
},
1716
fields: [],
1817
};

packages/dev/src/payload/collections/users.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const Users: CollectionConfig<"users"> = {
2020
requireEmail: true,
2121
requireUsername: false,
2222
},
23-
useSessions: false, // TODO: Database sessions currently not working
2423
},
2524
defaultPopulate: {
2625
id: true,

packages/payload-authjs/src/payload/collection/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ export const generateUsersCollection = (
122122
...authOptions,
123123
strategies: [AuthjsAuthStrategy(collection), ...(authStrategies ?? [])],
124124
// Disable local strategy if not explicitly enabled
125-
...(pluginOptions.enableLocalStrategy === true ? {} : { disableLocalStrategy: true }),
125+
...(pluginOptions.enableLocalStrategy === true
126+
? {
127+
// Database sessions not working with local strategy
128+
useSessions: false,
129+
}
130+
: { disableLocalStrategy: true }),
126131
};
127132

128133
// Add hooks to users collection

packages/payload-authjs/src/payload/plugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export interface AuthjsPluginConfig {
4040
* Enable the default local strategy from Payload CMS (experimental)
4141
* @see https://payloadcms.com/docs/authentication/jwt
4242
*
43+
* ! This does not work with database sessions (auth.useSessions: true)
44+
*
4345
* @default false
4446
*/
4547
enableLocalStrategy?: boolean;

packages/payload-authjs/src/types/payload.config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ export default buildConfig({
1717
collections: [
1818
{
1919
slug: "users-with-local-strategy",
20-
auth: {
21-
useSessions: false,
22-
},
2320
fields: [],
2421
},
2522
],

0 commit comments

Comments
 (0)