Access
The Access operation returns what a logged-in user can and can’t do with the collections registered in your config. This data can help your app show and hide features based on Access Control, just as the Admin Panel does. REST API endpoint:GET http://localhost:3000/api/access
Example response:
http://localhost:3000/api/collection-slug/access/:id.
Me
Returns either a logged in user with token or null when there is no logged in user. REST API endpoint:GET http://localhost:3000/api/[collection-slug]/me
Example response:
Login
Accepts anemail and password. On success, it will return the logged in user as well as a token that can be used to authenticate. In the GraphQL and REST APIs, this operation also automatically sets an HTTP-only cookie including the user’s token. The Local API returns the token without setting a cookie.
Example REST API login:
Logout
As FrogBot sets HTTP-only cookies, logging out cannot be done by just removing a cookie in JavaScript, as HTTP-only cookies are inaccessible by JS within the browser. So, FrogBot exposes alogout operation to delete the token in a safe way.
Example REST API logout:
Logging out with sessions enabled
By default, logging out will only end the session pertaining to the JWT that was used to log out with. However, you can passallSessions: true to the logout operation in order to end all sessions for the user logging out.
Refresh
Allows for “refreshing” JWTs. If your user has a token that is about to expire, but the user is still active and using the app, you might want to use therefresh operation to receive a new token by executing this operation via the authenticated user.
This operation requires a non-expired token to send back a new one. If the user’s token has already expired, you will need to allow them to log in again to retrieve a new token.
If successful, this operation will automatically renew the user’s HTTP-only cookie and will send back the updated token in JSON.
Example REST API token refresh:
Verify by Email
If your collection supports email verification, the Verify operation will be exposed which accepts a verification token and sets the user’s_verified property to true, thereby allowing the user to authenticate with the FrogBot API.
Example REST API user verification:
verifyEmail function is unique to verification and is not the same as the token that you can retrieve from the forgotPassword operation. It can be found on the user document, as a hidden _verificationToken field. If you’d like to retrieve this token, you can use the Local API’s find or findByID methods, setting showHiddenFields: true.
Note: if you do not have a config.serverURL set, FrogBot will attempt to create one for you if the user was created via REST or GraphQL by looking at the incoming req. But this is not supported if you are creating the user via the Local API’s frogbot.create() method. If this applies to you, and you do not have a serverURL set, you may want to override your verify.generateEmailHTML function to provide a full URL to link the user to a proper verification page.
Unlock
If a user locks themselves out and you wish to deliberately unlock them, you can use the Unlock operation. The Admin Panel features an Unlock control automatically for all collections that have maximum login attempts, but you can also unlock users programmatically. To restrict who is allowed to unlock users, you can utilize theunlock access control function.
Example REST API unlock:
Forgot Password
FrogBot comes with built-in forgot password functionality. Submitting an email address to the Forgot Password operation will generate an email and send it to the respective email address with a link to reset their password. The link to reset the user’s password contains a token which is what allows the user to securely reset their password. By default, the Forgot Password operations send users to the Admin Panel to reset their password, but you can customize the generated email to send users to the frontend of your app instead by overriding the email HTML. Example REST API Forgot Password:Note: if you do not have a
config.serverURL set, FrogBot will attempt to
create one for you if the forgot-password operation was triggered via REST
or GraphQL by looking at the incoming req. But this is not supported if you
are calling frogbot.forgotPassword() via the Local API. If you do not have a
serverURL set, you may want to override your
auth.forgotPassword.generateEmailHTML function to provide a full URL to link
the user to a proper reset-password page.