npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

medusa-facebook-login-logic

v1.0.0

Published

Ported Facebook Login logic from B&B_ui project.

Downloads

25

Readme

medusa-facebook-login-logic

A React hook library for handling Facebook OAuth authentication with Medusa.js backend.

Installation

Local Development (npm link)

# In the facebook-login-logic directory
npm link

# In your project directory
npm link medusa-facebook-login-logic

Production

npm install medusa-facebook-login-logic

Usage

Basic Login Button

import { useFacebookAuth } from 'medusa-facebook-login-logic'
import { sdk } from '@lib/config' // Your Medusa SDK instance

function FacebookLoginButton() {
  const { login, isLoading, error } = useFacebookAuth({ 
    sdk,
    productionDomain: 'yourdomain.com' // Optional
  })

  return (
    <button onClick={login} disabled={isLoading}>
      {isLoading ? 'Loading...' : 'Login with Facebook'}
    </button>
  )
}

Callback Handler

import { useFacebookAuth } from 'medusa-facebook-login-logic'
import { useSearchParams } from 'next/navigation'

function FacebookCallback() {
  const searchParams = useSearchParams()
  const queryParams = Object.fromEntries(searchParams.entries())

  const { customer, error, needsReLogin, isLoading } = useFacebookAuth({
    sdk,
    queryParams,
    onSuccess: (customer) => {
      console.log('Login successful:', customer)
      // Redirect to dashboard
    },
    onError: (error) => {
      console.error('Login failed:', error)
    },
    onNeedsReLogin: (email) => {
      console.log('Please login again with:', email)
    }
  })

  if (isLoading) return <div>Processing...</div>
  if (error) return <div>Error: {error}</div>
  if (needsReLogin) return <div>Please login again</div>
  
  return <div>Welcome {customer?.email}</div>
}

API

useFacebookAuth(props)

Props

| Prop | Type | Required | Default | Description | |------|------|----------|---------|-------------| | sdk | any | Yes | - | Medusa SDK instance | | baseUrl | string | No | Auto-detected | Base URL for redirects | | productionDomain | string | No | - | Production domain (e.g., 'example.com') | | callbackPath | string | No | /auth/customer/facebook/callback | OAuth callback path | | queryParams | Record<string, string> | No | - | OAuth callback query parameters | | onSuccess | (customer) => void | No | - | Success callback | | onError | (error: string) => void | No | - | Error callback | | onNeedsReLogin | (email: string) => void | No | - | Re-login required callback |

Returns

| Property | Type | Description | |----------|------|-------------| | login | () => Promise<void> | Initiates Facebook login flow | | isLoading | boolean | Loading state | | error | string \| null | Error message if any | | customer | any | Customer data after successful auth | | needsReLogin | boolean | Whether user needs to re-authenticate | | processCallback | () => Promise<void> | Manually process callback |

Environment Variables

The library automatically detects these environment variables:

  • NEXT_PUBLIC_BASE_URL - Base URL for your application
  • NEXT_PUBLIC_MEDUSA_STOREFRONT_URL - Medusa storefront URL

Features

  • ✅ Automatic redirect URI handling
  • ✅ Customer creation on first login
  • ✅ Token refresh management
  • ✅ Error handling with retry logic
  • ✅ TypeScript support
  • ✅ No hardcoded values

License

MIT