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

disc-auth.js

v1.4.0

Published

A Discord OAuth2 Handler

Downloads

17

Readme

disc-auth.js

Installation

npm i disc-auth.js

Requirements

・You must have nodejs v14 or up

Table of Contents

Class

Client

This is the main class that you initalize to perform all the requests to the API

Constructor

new Client({
  secret: "abcd",
  id: "1234",
  uri: "https://nevergonnagiveyou.up/login",
  scopes: "identify guilds",
  debug: true
})

Parameters

  • secret - The Client's secret
  • id - The Client's id
  • uri - The redirect URI for your OAuth2 app
  • scopes - Scopes for your app. Must be seperated by a space " " (eg. "identify guilds") MUST NOT BE AN ARRAY
  • debug - Default is false. When turned into true it'll log everything that makes a request to the API

Properties

  • client - This stores client id's secret's and the uri
    • secret - The Client's secret
    • id - The Client's id
    • uri - The redirect URI for your OAuth2 app
  • scopes - The scopes for the OAuth2 app (eg. "identify guilds")
  • debug - Default is false. When turned into true it'll log everything that makes a request to the API
  • app - This contains information about the app and that information will be the User and the access_token and refresh_token
    • tokens
      • access_token - The access_token for the app
      • refresh_token - The refresh_token used for when refreshing the current access_token
      • expires_at - When its gonna expire (With an estimated time)
      • expires_in - When its gonna expire (Without the estimated time)
    • user - The user class. Click here

Methods

getToken()

await Client.getToken(code)

Converts a code from the query string into an access_token

Parameters

  • code - The code from the query string (eg. https://idk.com/login?code=abcd)

Returns Promise

refreshToken()

await Client.refreshToken()

This refreshes an access_token to a new one. The package automatically refresh the token when the current one expires!

Returns Promise

getUser()

await Client.getUser()

Gets the user who authenticated (Requires the identify scope)

Returns Promise

getGuilds()

await Client.getGuilds()

Gets the user's guilds then put it in the Client.app.user.guilds object (Must have a user authenticated/Client.app.user exist and "guilds" scope)

Returns Promise

User

Constructor

new User(userData)

Parameters

Properties

  • raw - The raw data of a user.
  • id - The id of the user
  • username - The username of the user (eg. Slay)
  • discriminator - The discriminator of the user (eg. 0098)
  • tag - Combined with the username and the discriminator. Seperated by a "#" (eg. Slay#0098)
  • email - The email of the user (May return null if the app has identify scope but not email)
  • nitro - The type of nitro the user currently has (eg. None or Nitro Classic or Nitro)
  • guilds - An array of guild objects.

Methods

displayAvatarURL

Gets a user's avatar

await User.displayAvatarURL({
  dynamic: true
})

Parameters

  • {}
  • dynamic - Default is false, if true the format will dynamically change to gif for animated avatars.

Returns String

Support

Need help with this package? Come on down to our discord server and go to the #disc・auth under support channel to get some help.