Skip to main content
This is an advanced feature, so only attempt this if you are an experienced developer. Otherwise, just let FrogBot’s built-in authentication handle user auth for you.Development Note: Changes to custom authentication strategies require a full server restart to take effect. Auth strategies are not hot-reloaded during development. Consider using tools like nodemon for auto-restart functionality.

Creating a strategy

A strategy authenticates a user from information in an incoming request. A strategy is made up of the following: The authenticate function is passed the following arguments: authenticate returns an AuthStrategyResult:

Example strategy

Import AuthStrategy from frogbot to type your strategy, then add it to an auth collection’s strategies array. Return { user: null } when the credentials are missing or do not identify a user. Otherwise, return the user document with its collection slug. You can also return responseHeaders: new Headers(...) when canSetHeaders is true. This example uses a per-user code as a credential. Keep it secret and send it only over HTTPS. With the local strategy disabled, custom user fields such as email may be nullable; return the complete document rather than requiring an email address.

When a strategy throws

If your strategy throws, FrogBot logs the error on the server with the collection and strategy names, then tries the next strategy. If no strategy authenticates a user, the request remains anonymous and normal access control applies. The authentication response never includes the reason the strategy failed.