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 🙏

© 2024 – Pkg Stats / Ryan Hefner

social-auth-np

v1.0.5

Published

Makes your life easy integrating social login

Downloads

4

Readme

social-auth-np

Making life easier to integrate social signup in applications

NPM

Install

npm install --save social-auth-np

Examples

https://github.com/keyrunpay/social-auth-np/tree/master/example

Pulling Examples to your local file

npx degit github:keyrunpay/social-auth-np/example#master social-auth

Usage Client Side

Social Login Button Component

import React from "react";
import socialAuthNp from "social-auth-np";

export default function FacebookAuthComponent() {
  const loginOption = {
    ...socialAuthNp.getClientSideOauthOption("facebook"), // available auth options "facebook", "google", "github", "linkedin"
    client_id: "FB_CLIENT_ID",
    redirect_uri: "http://localhost:3000/facebook_auth_callback",
  };
  const fbLoginUrl = socialAuthNp.getOauthUrl("facebook", loginOption); // available auth options "facebook", "google", "github", "linkedin"

  return (
    <div className="App">
      <br />
      <a href={fbLoginUrl}>
        <button>Login with facebook</button>
      </a>
    </div>
  );
}

Fb Redirected Page Component

import React from "react";
import socialAuthNp from "social-auth-np";
import Axios from "axios";

export default function FacebookCallback() {
  const code = socialAuthNp.parseUrl(window.location.search).code;
  const [resp, setResp] = React.useState(null);

  const submitCode = async () => {
    try {
      const { data } = await Axios.get(
        "http://localhost:6001/auth/facebook?code=" + code
      );
      setResp(data);
    } catch (err) {
      setResp(err.response.data);
    }
  };

  React.useEffect(() => {
    if (code) submitCode();
  }, [code]);

  return (
    <div>
      <p>FB Code is: {code}</p>
      <p>Please wait submitting code for verification..</p>
      {resp && <p>{JSON.stringify(resp)}</p>}
    </div>
  );
}

Usage Server Side

const socialAuthNp = require("social-auth-np");

const authFacebook = async (req, res) => {
  const { code } = req.query;

  if (!code) {
    res.status(401).json({ error: "Code is required" });
    return;
  }

  const params = {
    client_id: "CLIENT_ID",
    client_secret: "CLIENT_SECRET",
    redirect_uri: "http://localhost:3000/facebook_auth_callback",
    code,
  };

  try {
    const { data } = await socialAuthNp.getAccessToken("facebook", params); // available auth options "facebook", "google", "github", "linkedin"
    const access_token = data.access_token;
    if (!access_token) {
      res.status(401).json({ error: "Expired or bad code" });
      return;
    }
    const response = await socialAuthNp.getUserInfo("facebook", access_token); // available auth options "facebook", "google", "github", "linkedin"
    /*
        I hope from here you will use the info that is generated to match with your
        own database info and do issue JWT token  or make a session for user
    */
    res.json(response.data);
  } catch (err) {
    res.status(401).json({ error: "Expired or bad code or network issue" });
  }
};

module.exports = authFacebook;

Information

The example provided here is in ReactJS but this package is compatible with all fontend framework like angular, vue, react.... Feel free to use and create ans issue if you find any bug

About Author

Kiran Neupane [email protected] Facebook

Support This Package

React Tutor @ Youtube

Channel Name: Buggged Youtube Website

License

MIT © keyrunpay