← @mortar-kit/auth

allowMembersfunction

import { allowMembers } from '@mortar-kit/auth'

function allowMembers<Field extends string = never>(options: AllowMembersOptions<Field>): (input: AuthorizeInput) => Promise<MemberUser<Field> | null>

An authorize that lets in anyone whose address is in a document of collection (compared case-insensitively). Removing the document locks them out on their next request. It lists the collection each time, which suits the handful of members a small site has.

Parameters

Returns

(input: AuthorizeInput) => Promise<MemberUser<Field> | null>

Example

export const members = defineCollection({
  name: 'members',
  label: 'Members',
  fields: { email: fields.text({ label: 'Email', required: true }), name: fields.text({ label: 'Name' }) },
});
createAuth({ methods, secret, authorize: allowMembers({ content, collection: 'members' }) });

// With roles: the user gets the member's `role` too.
authorize: allowMembers({ content, collection: 'members', fields: ['role'] }),