npm.io
2.22.7 • Published 4d ago

@medusajs/auth-github

Licence
MIT
Version
2.22.7
Deps
0
Size
22 kB
Vulns
0
Weekly
0
Stars
36.8K

Medusa logo

@medusajs/auth-github

Documentation | Website

Building blocks for digital commerce

Medusa is released under the MIT license. PRs welcome! Discord Chat Follow @medusajs

GitHub Auth Module Provider for Medusa: lets users and customers log in with their GitHub account through OAuth 2. Use it to add "Log in with GitHub" for customers, admin users, or custom actor types. It ships with @medusajs/medusa and is registered through the @medusajs/medusa/auth-github path.

At a glance

Package @medusajs/auth-github
Type Module Provider (Auth Module)
Provider ID github
Registered by default No
Import from @medusajs/medusa/auth-github

Installation

No installation needed. The provider is a dependency of @medusajs/medusa.

Usage

Register the provider in the Auth Module's providers array in medusa-config.ts. Passing providers replaces the default list, so keep emailpass if you still need email/password login:

import { defineConfig } from "@medusajs/framework/utils"

module.exports = defineConfig({
  // ...
  modules: [
    {
      resolve: "@medusajs/medusa/auth",
      options: {
        providers: [
          {
            resolve: "@medusajs/medusa/auth-emailpass",
            id: "emailpass",
          },
          {
            resolve: "@medusajs/medusa/auth-github",
            id: "github",
            options: {
              clientId: process.env.GITHUB_CLIENT_ID,
              clientSecret: process.env.GITHUB_CLIENT_SECRET,
              callbackUrl: process.env.GITHUB_CALLBACK_URL,
            },
          },
        ],
      },
    },
  ],
})

The provider's id is the one used in authentication routes, such as /auth/customer/github.

Configuration

Option Type Description Default
clientId string Required. The OAuth client ID of your GitHub app. -
clientSecret string Required. The OAuth client secret of your GitHub app. -
callbackUrl string Required. The URL GitHub redirects to after authentication. Can be overridden per request with a callback_url body parameter. -
Environment variable Description
GITHUB_CLIENT_ID Value for clientId, as used in the example above.
GITHUB_CLIENT_SECRET Value for clientSecret, as used in the example above.
GITHUB_CALLBACK_URL Value for callbackUrl, as used in the example above.

Resources

Keywords