#disableLocalStrategy example

1 messages · Page 1 of 1 (latest)

deft pine
#

I've created a collection like this : ```
export const Users: CollectionConfig = {
slug: 'users',
auth: {
disableLocalStrategy: true,
tokenExpiration: 7200, // 2 hours
cookies: {
secure: process.env.NODE_ENV === 'production',
sameSite: 'Lax',
},
strategies: [
{
name: 'steam',
authenticate: async ({ payload, headers }) => {
const steamId = headers.get('steam-id')
if (!steamId) {
return {
user: null,
}
}

      // Try to find existing user
      const usersQuery = await payload.find({
        collection: 'users',
        where: {
          steamId: {
            equals: steamId,
          },
        },
      })

      if (usersQuery.docs.length > 0) {
        return {
          user: {
            ...usersQuery.docs[0],
            collection: 'users',
          },
        }
      }

      // Create new user if doesn't exist
      try {
        const newUser = await payload.create({
          collection: 'users',
          data: {
            steamId,
          },
        })

        return {
          user: {
            ...newUser,
            collection: 'users',
          },
        }
      } catch (error) {
        console.error('Failed to create user:', error)
        return {
          user: null,
        }
      }
    },
  },
],

},
admin: {
useAsTitle: 'steamId',
},
fields: [
{
name: 'steamId',
type: 'text',
required: true,
unique: true,
index: true,
saveToJWT: true,
},
],
}

deft pine
#

Do I understand correctly that when I use disableLocalStrategy: true, then PayloadCMS is no longer doing token and cookie creation for me...it all has to be done by myself now? I try to auth user this way: ```
const { user, permissions, responseHeaders } = await payload.auth({
headers,
req,
})

#

is disableLocalStrategy: true disables not only email/password authentication, but the entire PayloadCMS authentication infrastructure?