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

discord-login-popup

v2.0.7

Published

The `discord-login-popup` package offers a streamlined solution for integrating Discord OAuth2 authentication into web applications. This library facilitates user login through a popup window, simplifying the process of obtaining user information and acce

Downloads

654

Readme

Discord Login Popup 🎯

The discord-login-popup package offers a streamlined solution for integrating Discord OAuth2 authentication into web applications. This library facilitates user login through a popup window, simplifying the process of obtaining user information and access tokens from Discord's API. The implementation is designed for ease of use, making it an ideal choice for developers who need to add Discord authentication with minimal setup.

Features 🌟

  • Easy Integration: Quickly add Discord OAuth2 login to your web application.
  • Customizable: Configure client ID, redirect URI, and scope settings to tailor the authentication flow.
  • Token Management: Simplifies the process of retrieving and managing Discord access tokens.
  • User Information: Effortlessly obtain user information from Discord after authentication.

Installation 📦

To install the discord-login-popup library, you can use npm or yarn:

# Using npm
npm install discord-login-popup

# Using yarn
yarn add discord-login-popup

Demo 😈

To see a live demo of the discord-login-popup in action, check out the Demo Page.

Hosted storybook

Usage 🎉

Requirements 🎓

Open a popup window with the discord login page. Upon login, the popup window will close and the token will be passed to the parent window.

Steps 🛠️

  1. As integrator, you need to provide the client id, redirect url, and scopes. Make sure to obtain a client id from the Discord Developer Portal.

  2. You also need to provide a callback function that will be called when the discord login popup is closed and the token is passed to the parent window.

  3. You must host a page that will open inside popup window after discord redirect. This page must inject the discord-login-token-detector.js script from this repository. Feel free to download the script and host it yourself. Example: discord-login.html

Usage in Typescript 📦

Here’s a basic example of how to use the discord-login-popup package in a React application:

import { discordLoginPopup, OnSuccessTokenParams } from 'discord-login-popup';

// Get your client ID from the Discord Developer Portal
// https://discord.com/developers/applications
const clientId = 'YOUR_DISCORD_CLIENT_ID';
// Redirect URL must be the same as the one you set in the Discord Developer Portal
// This is the URL for a page that will open in the popup. This page must inject the `static/discord-login-token-detector.js` script from this repository
// Checkout the static/discord-login.html file for an example of how to use this page
const redirectUri = 'YOUR_REDIRECT_URI';
const scopes = 'identify';
// The response type can be either 'token' or 'code'
// If you choose 'token', the popup will return the access token
// If you choose 'code', the popup will return the code
// Make sure you cast the data to the correct type OnSuccessTokenParams or OnSuccessCodeParams
const responseType = 'token';

const login = () => {
    discordLoginPopup({
        discordAppClientId: clientId,
        redirectUrl: redirectUri,
        scopes: scopes,
        responseType: responseType,
        onStart: () => console.log('Login started'),
        onError: (data) => console.error('Login failed. Reason:', data.error_description, data.error),
        onSuccess: (data) => console.log('Login successful. Data:', data as OnSuccessTokenParams),
        onClose: () => console.log('Popup closed'),
    });
};

// Call the login function on a button click or any other event
login();

Usage in React 📦

Checkout the React Integration Story for a live example of how to use the discord-login-popup package in a React application.

Usage in Next.js 📦

Checkout this Next.js repo for an example of how to use the discord-login-popup package inside a NextJS application.

Contributing 🤝

Contributions are welcome! If you have any ideas, suggestions, or issues, please open an issue or submit a pull request.

License 📋

This project is licensed under the MIT License. See the LICENSE file for more details.