I am creating a discord bot dashboard website with express and i've been getting this error but can seem to fix it: TypeError: Cannot read property 'access_token' of undefined. When I run the code everything is completely working but the error still pops up.
This is my entire page:
const router = express.Router();
const OAuthClient = require('disco-oauth');
const AuthClient = new OAuthClient(
'732404499209256980',
'bqX8W8RXQl-lqgbjxVqys7dlRcUzUZAk'
);
const inviteURL ='https://discord.com/oauth2/authorize?client_id=732404499209256980&permissions=2147479255&scope=bot',
loginURL = `https://discord.com/api/oauth2/authorize?client_id=732404499209256980&redirect_uri=https%3A%2F%2Fvalbot-testing.valblaze.repl.co%2Fauth&response_type=code&scope=identify%20guilds`;
AuthClient.setRedirect(`https://valbot-testing.valblaze.repl.co/auth`);
AuthClient.setScopes('identify', 'guilds');
router.use(async (req, res, next) => {
const key = req.cookies.get('key');
res.locals.user = await AuthClient.getUser(key);
next();
});
router.get('/', (req, res) => res.render('home'));
router.get('/dashboard', (req, res) => {
res.render('dashboard/index');
});
router.get('/invite', (req, res) => res.redirect(inviteURL));
router.get('/login', (req, res) => res.redirect(loginURL));
router.get('/auth', async (req, res) => {
const key = await AuthClient.getAccess(req.query.code);
res.cookies.set('key', key);
res.redirect('/dashboard');
});
router.get('*', (req, res) => res.render(`errors/404.pug`));
module.exports = router;
but this seems to be the code breaking it:
const key = req.cookies.get('key');
res.locals.user = await AuthClient.getUser(key);
whenever I call await AuthClient.getUser(key) it breaks and i've tried logging the key to the console it works fine just like a normal key.
Is there anything i'm missing?