Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

node.js - UnhandledPromiseRejectionWarning: DiscordHTTPError: 401 Unauthorized on GET /api/v7/users/@me

I'm making a login system with Discord using the discord-oauth package ... But it gives this error of unauthorized (UnhandledPromiseRejectionWarning: DiscordHTTPError: 401 Unauthorized on GET /api/v7/users/@me)

Code:

const router = require('express').Router()
const crypto = require('crypto')
const DiscordOauth2 = require('discord-oauth2') 
const request = require('snekfetch')

const rateLimit = require('../middleware/limiterBotControler.js')
const baseUrl = 'https://discord.com/api/v7/'

const oauth = new DiscordOauth2({
    clientId: '782761260620972034',
    clientSecret: '',
    redirectUri: 'http://localhost:8080/login/discord/callback'
})

router.get('/login', (req, res) => {

    let url = oauth.generateAuthUrl({
        scope: ['identify', 'email', 'guilds'],
        state: crypto.randomBytes(16).toString('hex')
    })

    return res.redirect(url)
})

router.get('/login/discord/callback', (req, res) => {
    let code = req.query.code

    oauth.tokenRequest({
        code: code,
        grantType: 'authorization_code',
        scope: ['identify', 'email', 'guilds']
    }).then((refresh_token) => {
        oauth.getUser(refresh_token).then(console.log)
    })


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

eita em snar, sei nao mano, talvez seja o windows.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...