Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 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)
    })

question from:https://stackoverflow.com/questions/65854932/unhandledpromiserejectionwarning-discordhttperror-401-unauthorized-on-get-api

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...