@gadgetinc/auth is a deprecated plugin package that implements user authentication for your Gadget app.
@gadgetinc/auth has been replaced with auth features built in to Gadget itself and will no longer receive updates. If you are using
@gadgetinc/auth, Gadget recommends migrating to framework version 1.0 and the built-in auth features that
come with it. To migrate you must remove the @gadgetinc/auth package, reach out in our Discord
for more information and support in doing so.
Installation
terminal
yarnadd @gadgetinc/auth
# or
npminstall --save @gadgetinc/auth
Registering the plugin
This plugin can be registered using a route plugin, which is a file in the routes folder starting with +, e.g. routes/+auth.js:
gadgetManagedCredentials - whether or not you wish to use Gadget's developer OAuth credentials. These credentials are only intended for quick setup in your Development environment, and should be updated before you deploy your app to Production. Defaults to false.
api - your Gadget api client
redirectToSignIn - if a user is not signed in using the preValidation check, then redirect the user to the path specified by signInPath. Defaults to false
signInPath - the path to your login page. This is where users will be redirected if redirectToSignIn is set to true. Defaults to /signin
providers - an array of authentication providers
type - currently the only available type is "google"
clientId - Google OAuth client id
clientSecret - Google OAuth client secret
scopes - optional OAuth scopes to request from the user. Defaults to ["email", "profile"] for Google
transformUser - by default the plugin will only attempt to set the user model's firstName, lastName, and email fields. If you've edited or added more fields and want to customize this behavior, this function is provided the decoded id_token and must - return the input to the user model's create action.
Protecting routes
To ensure only signed-in users have access to a route, you can protect it with the preValidation hook: