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

socialauthify

v1.0.6

Published

A cross-platform OAuth login package supporting multiple providers

Readme

socialauthify

A flexible social authentication package supporting multiple OAuth providers for React, Vue, and Svelte applications.

Features

  • Multiple OAuth providers:
    • Google
    • Microsoft
    • Facebook
    • LinkedIn
    • GitHub
  • Built-in token management
  • Loading and error states
  • TypeScript support
  • Framework-agnostic
  • Customizable styling

Installation

npm install socialauthify

Quick Start

React

import React, { useState } from 'react';
import { setConfig, googleLogin, microsoftLogin, /* ... */ } from 'socialauthify';

// Configure OAuth providers
setConfig({
  google: {
    clientId: 'YOUR_GOOGLE_CLIENT_ID',
    clientSecret: 'YOUR_GOOGLE_CLIENT_SECRET',
    redirectUri: 'http://localhost:3000/home',
    scope: 'email profile openid'
  },
  microsoft: {
    clientId: 'YOUR_MICROSOFT_CLIENT_ID',
    clientSecret: 'YOUR_MICROSOFT_CLIENT_SECRET',
    redirectUri: 'http://localhost:3000/home',
    scope: 'user.read openid profile email'
  }
  // ... other providers
});

function Login({ onLoginSuccess, onError }) {
  const [loading, setLoading] = useState(false);
  const [error, setError] = useState(null);

  const handleLogin = async (provider, loginFunction) => {
    setLoading(true);
    try {
      sessionStorage.setItem('oauth_provider', provider.toLowerCase());
      await loginFunction();
    } catch (error) {
      const errorMessage = `${provider} login failed: ${error.message}`;
      setError(errorMessage);
      onError?.(errorMessage);
    } finally {
      setLoading(false);
    }
  };

  return (
    <div>
      {error && <div>{error}</div>}
      {loading && <div>Loading...</div>}
      
      <button onClick={() => handleLogin('Google', googleLogin)}>
        Login with Google
      </button>
      <button onClick={() => handleLogin('Microsoft', microsoftLogin)}>
        Login with Microsoft
      </button>
      {/* Add other provider buttons */}
    </div>
  );
}

Vue

<!-- Login.vue -->
<template>
  <div>
    <div v-if="error" class="error">{{ error }}</div>
    <div v-if="loading" class="loading">Loading...</div>

    <button 
      v-for="provider in providers" 
      :key="provider.name"
      @click="handleLogin(provider.name, provider.login)"
      :style="provider.style"
    >
      Login with {{ provider.name }}
    </button>
  </div>
</template>

<script>
import { ref } from 'vue';
import { 
  setConfig, 
  googleLogin, 
  microsoftLogin,
  handleGoogleCallback,
  handleMicrosoftCallback
} from 'socialauthify';

// Configure OAuth providers
setConfig({
  google: {
    clientId: 'YOUR_GOOGLE_CLIENT_ID',
    clientSecret: 'YOUR_GOOGLE_CLIENT_SECRET',
    redirectUri: 'http://localhost:3000/home',
    scope: 'email profile openid'
  },
  microsoft: {
    clientId: 'YOUR_MICROSOFT_CLIENT_ID',
    clientSecret: 'YOUR_MICROSOFT_CLIENT_SECRET',
    redirectUri: 'http://localhost:3000/home',
    scope: 'user.read openid profile email'
  }
});

export default {
  setup() {
    const loading = ref(false);
    const error = ref(null);

    const providers = [
      { 
        name: 'Google', 
        login: googleLogin,
        callback: handleGoogleCallback,
        style: { backgroundColor: '#4285f4', color: 'white' }
      },
      { 
        name: 'Microsoft', 
        login: microsoftLogin,
        callback: handleMicrosoftCallback,
        style: { backgroundColor: '#00a4ef', color: 'white' }
      }
      // Add other providers
    ];

    const handleLogin = async (provider, loginFunction) => {
      loading.value = true;
      try {
        sessionStorage.setItem('oauth_provider', provider.toLowerCase());
        await loginFunction();
      } catch (err) {
        error.value = `${provider} login failed: ${err.message}`;
      } finally {
        loading.value = false;
      }
    };

    return {
      loading,
      error,
      providers,
      handleLogin
    };
  }
};
</script>

Svelte

<!-- Login.svelte -->
<script>
  import { onMount } from 'svelte';
  import { 
    setConfig, 
    googleLogin, 
    microsoftLogin,
    handleGoogleCallback,
    handleMicrosoftCallback 
  } from 'socialauthify';

  // Configure OAuth providers
  setConfig({
    google: {
      clientId: 'YOUR_GOOGLE_CLIENT_ID',
      clientSecret: 'YOUR_GOOGLE_CLIENT_SECRET',
      redirectUri: 'http://localhost:3000/home',
      scope: 'email profile openid'
    },
    microsoft: {
      clientId: 'YOUR_MICROSOFT_CLIENT_ID',
      clientSecret: 'YOUR_MICROSOFT_CLIENT_SECRET',
      redirectUri: 'http://localhost:3000/home',
      scope: 'user.read openid profile email'
    }
  });

  let loading = false;
  let error = null;

  const providers = [
    {
      name: 'Google',
      login: googleLogin,
      callback: handleGoogleCallback,
      style: 'background-color: #4285f4; color: white;'
    },
    {
      name: 'Microsoft',
      login: microsoftLogin,
      callback: handleMicrosoftCallback,
      style: 'background-color: #00a4ef; color: white;'
    }
    // Add other providers
  ];

  async function handleLogin(provider, loginFunction) {
    loading = true;
    try {
      sessionStorage.setItem('oauth_provider', provider.toLowerCase());
      await loginFunction();
    } catch (err) {
      error = `${provider} login failed: ${err.message}`;
    } finally {
      loading = false;
    }
  }

  onMount(() => {
    const urlParams = new URLSearchParams(window.location.search);
    const code = urlParams.get('code');
    const provider = sessionStorage.getItem('oauth_provider');
    
    if (code && provider) {
      handleCallback(code, provider);
    }
  });
</script>

{#if error}
  <div class="error">{error}</div>
{/if}

{#if loading}
  <div class="loading">Loading...</div>
{/if}

<div class="button-container">
  {#each providers as provider}
    <button
      on:click={() => handleLogin(provider.name, provider.login)}
      style={provider.style}
      disabled={loading}
    >
      Login with {provider.name}
    </button>
  {/each}
</div>

<style>
  .button-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
    margin: 40px auto;
  }

  button {
    padding: 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
  }

  .error {
    color: red;
    text-align: center;
    margin-bottom: 10px;
    padding: 10px;
    background-color: #ffebee;
    border-radius: 4px;
  }

  .loading {
    text-align: center;
    color: #666;
    margin-bottom: 10px;
  }
</style>

Configuration Options

| Provider | Required Scopes | |-----------|----------------| | Google | email profile openid | | Microsoft | user.read openid profile email | | Facebook | email public_profile | | LinkedIn | openid profile email | | GitHub | read:user user:email |

TypeScript Support

Types are included and no separate @types package is needed.

Error Handling

The package provides detailed error information that you can handle in your application:

try {
  await handleGoogleCallback(code);
} catch (error) {
  console.error('Provider error:', error.message);
}

Security Best Practices

  1. Always use environment variables for client secrets
  2. Implement proper state validation
  3. Use HTTPS in production
  4. Never store tokens in localStorage
  5. Implement proper session management

License

MIT

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.