🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

@gadgetinc/auth

Package Overview
Dependencies
Maintainers
6
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gadgetinc/auth

`@gadgetinc/auth` is a `fastify` plugin that helps manage on platform authentication in [Gadget](https://gadget.dev).

latest
npmnpm
Version
0.4.0
Version published
Maintainers
6
Created
Source

@gadgetinc/auth

@gadgetinc/auth is a fastify plugin that helps manage on platform authentication in Gadget.

Features

This library implements the following features:

  • registers route handlers for OAuth start, callback, and sign out.
  • provides a utility for protecting HTTP routes using preValidation hooks.
  • manages sessions and users in your Gadget app's user and session model.

Installation

yarn add @gadgetinc/auth
# or
npm install --save @gadgetinc/auth

Usage

This plugin can be registered with Gadget in either a boot plugin or route plugin.

To register the plugin:

// routes/+auth.js
import { Auth } from "@gadgetinc/auth";
import { api } from "gadget-server";

export default function (server) {
  server.register(Auth, {
    api,
    providers: [
      {
        type: "google",
        clientId: process.env.GOOGLE_CLIENT_ID,
        clientSecret: process.env.GOOGLE_CLIENT_SECRET,
      },
    ],
  });
}

To protect a route:

// routes/GET-protected-route.js
const { preValidation } = require("@gadgetinc/auth");

module.exports = async function ({ reply }) {
  await reply.send("this is a protected route!");
};

module.exports.options = {
  preValidation,
};

Options

Plugin options

  • 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 to 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

FAQs

Package last updated on 19 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts