users collection. If exactly one auth collection exists, FrogBot uses it as the owner relationship for chat chats regardless of its slug. With multiple auth collections, set admin.user to choose one.
Here are some common use cases of Authentication in your own applications:
- Customer accounts for an e-commerce app
- User accounts for a SaaS product
- P2P apps or social sites where users need to log in and manage their profiles
- Online games where players need to track their progress over time
auth property in the Collection Config. Add auth.signIn for OAuth sign-in.
Admin Panel screenshot depicting an Admins Collection with Auth enabled
Config Options
Any Collection can opt-in to supporting Authentication. Once enabled, each Document that is created within the Collection can be thought of as a “user”. This enables a complete authentication workflow on your Collection, such as logging in and out, resetting their password, and more. To enable Authentication on a Collection, use theauth property in the Collection Config:
Tip: For default auth behavior, set
auth: true. This is a good starting
point for most applications.AuthEmailTemplate is ({ token, user }) => string | Promise<string>.
Cookie options
Disable local strategy
SetdisableLocalStrategy: true to remove the email, password, and lockout fields, and to make the login, forgot password, reset password, unlock, and email verification operations fail. Pass an object to change what is kept.
Login With Username
You can allow users to login with their username instead of their email address by setting theloginWithUsername property to true.
Example:
Auto-Login
For testing and demo purposes you may want to skip forcing the user to login in order to access your application. Typically, all users should be required to login, however, you can speed up local development time by enabling auto-login. To enable auto-login, set theautoLogin property in the FrogBot Config:
autoLogin defaults to false. To turn it on, pass an object:
Without
prefillOnly, every request that has no valid login token is authenticated as this user: the admin panel, REST and GraphQL requests, and frogbot.auth().
Auto-Refresh
Turning this property on will allow users to stay logged in indefinitely while their browser is open and on the admin panel, by automatically refreshing their authentication token before it expires. To enable auto-refresh for user tokens, setautoRefresh: true in the FrogBot Config. It defaults to false, which shows a prompt to stay logged in before the token expires:
Operations
All auth-related operations are available via FrogBot’s REST, Local, and GraphQL APIs. These operations are automatically added to your Collection when you enable Authentication. More details.Strategies
Out of the box FrogBot ships with three powerful Authentication strategies:- HTTP-Only Cookies
- JSON Web Tokens (JWT)
- API-Keys, through the API keys plugin
HTTP-Only Cookies
HTTP-only cookies are a highly secure method of storing identifiable data on a user’s device so that FrogBot can automatically recognize a returning user until their cookie expires. They are totally protected from common XSS attacks and cannot be read by JavaScript in the browser, unlike JWT’s. More details.JSON Web Tokens
JWT (JSON Web Tokens) can also be utilized to perform authentication. Tokens are generated onlogin, refresh and me operations and can be attached to future requests to authenticate users. More details.
API Keys
API keys come from the API keys plugin. They’re particularly useful when you want to authenticate against FrogBot from a third-party service. More details.Custom Strategies
There are cases where these may not be enough for your application. FrogBot is extendable by design so you can wire up your own strategy when you need to. More details.Access Control
Default auth fields includingemail, username, and password can be overridden by defining a custom field with the same name in your collection config. This allows you to customize the field — including access control — while preserving the underlying auth functionality. For example, you might want to restrict the email field from being updated once it is created, or only allow it to be read by certain user roles. You can achieve this by redefining the field and setting access rules accordingly.
Here’s an example of how to restrict access to default auth fields:
- Access functions will apply across the application — I.e. if
readaccess is disabled onemail, it will not appear in the Admin panel UI or API. - Restricting
readon theemailorusernamedisables the Unlock action in the Admin panel as this function requires access to a user-identifying field. - When overriding the
passwordfield, you may need to includehidden: trueto prevent duplicate fields being displayed in the Admin panel.