Skip to content

Commit a8f43dd

Browse files
committed
refactor: Add enableLocalStrategy plugin option instead of custom collection field
1 parent 25d4b8d commit a8f43dd

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

packages/dev/src/payload.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ export default buildConfig({
5252
},
5353
}),
5454
sharp,
55-
plugins: [authjsPlugin({ authjsConfig: nodeAuthConfig })],
55+
plugins: [authjsPlugin({ authjsConfig: nodeAuthConfig, enableLocalStrategy: true })],
5656
});

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ const Users: CollectionConfig = {
1515
auth: {
1616
useAPIKey: true,
1717
},
18-
custom: {
19-
enableLocalStrategy: true,
20-
},
2118
fields: [
2219
{
2320
name: "name",

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ export function PayloadAdapter({
6666

6767
let payloadUser: User;
6868
if (
69-
(await payload).collections[userCollectionSlug]?.config.custom.enableLocalStrategy ===
70-
true &&
69+
!(await payload).collections[userCollectionSlug]?.config.auth.disableLocalStrategy &&
7170
!(user as User).password
7271
) {
7372
// If the local strategy is enabled and the user does not have a password, bypass the password check
@@ -406,10 +405,7 @@ export function PayloadAdapter({
406405
verificationTokens: [token],
407406
};
408407

409-
if (
410-
(await payload).collections[userCollectionSlug]?.config.custom.enableLocalStrategy ===
411-
true
412-
) {
408+
if (!(await payload).collections[userCollectionSlug]?.config.auth.disableLocalStrategy) {
413409
// If the local strategy is enabled, bypass the password check
414410
payloadUser = (await createUserAndBypassPasswordCheck(payload, {
415411
collection: userCollectionSlug,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const generateUsersCollection = (
9595
...authOptions,
9696
strategies: [AuthjsAuthStrategy(collection, pluginOptions), ...(authStrategies ?? [])],
9797
// Disable local strategy if not explicitly enabled
98-
...(collection.custom?.enableLocalStrategy === true ? {} : { disableLocalStrategy: true }),
98+
...(pluginOptions.enableLocalStrategy === true ? {} : { disableLocalStrategy: true }),
9999
};
100100

101101
// Add hooks to users collection

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ export interface AuthjsPluginConfig {
2828
*/
2929
authjsConfig: NextAuthConfig;
3030

31+
/**
32+
* Enable the default local strategy from Payload CMS (experimental)
33+
* @see https://payloadcms.com/docs/authentication/jwt
34+
*
35+
* @default false
36+
*/
37+
enableLocalStrategy?: boolean;
38+
3139
/**
3240
* Customize the components that the plugin adds to the admin panel
3341
*/

0 commit comments

Comments
 (0)