npm.io
2.22.7 • Published 4d ago

@medusajs/auth-google

Licence
MIT
Version
2.22.7
Deps
2
Size
25 kB
Vulns
0
Weekly
0
Stars
35.8K

Medusa logo

@medusajs/auth-google

Documentation | Website

Building blocks for digital commerce

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

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

At a glance

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

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-google",
            id: "google",
            options: {
              clientId: process.env.GOOGLE_CLIENT_ID,
              clientSecret: process.env.GOOGLE_CLIENT_SECRET,
              callbackUrl: process.env.GOOGLE_CALLBACK_URL,
            },
          },
        ],
      },
    },
  ],
})

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

Configuration

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

Resources

Keywords