orels1 / discord-token-generator

An example discord oauth2 token generator
116 stars 75 forks source link

CLIENT_ID is not snowflake #5

Open pixeljellyfish opened 4 years ago

pixeljellyfish commented 4 years ago

i get this error when i go to press login but i the same discord.js

"Value \"undefined\" is not snowflake."

and this is the code const express = require('express');

const router = express.Router();

const CLIENT_ID = process.env.CLIENT_ID; const CLIENT_SECRET = process.env.CLIENT_SECRET; const redirect = encodeURIComponent('http://localhost:50451/api/discord/callback');

router.get('/login', (req, res) => { res.redirect(https://discordapp.com/api/oauth2/authorize?client_id=$%7BCLIENT_ID%7D&redirect_uri=http%3A%2F%2Flocalhost%2Fapi%2Fdiscord%26callback&response_type=code&scope=identify); });

module.exports = router;

Savedyou commented 4 years ago

Did you restart your computer after after adding the environment variables? If you print the CLIENT_ID in your code I think you will find that the variables don't exist yet until restart. Hope this helps

yuta0801 commented 4 years ago

Alternatively, you can set environment variables at runtime. This way doesn't need restarting computer, but instead needs to be set every time.

On Windows: set CLIENT_ID=id&& set CLIENT_SECRET=secret&& node server.js Or Mac/Linux: CLIENT_ID=id CLIENT_SECRET=secret node server.js

pixeljellyfish commented 4 years ago

i did restart my comptuer and where would i place the runtime variables

yuta0801 commented 4 years ago

Just replace id with your client id and secret with your client secret Let's say your client id is 000000000000000000 and your client secret id aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, you can run this command: On Windows: set CLIENT_ID=000000000000000000&& set CLIENT_SECRET=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&& node server.js Or Mac/Linux: CLIENT_ID=000000000000000000 CLIENT_SECRET=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa node server.js

pixeljellyfish commented 4 years ago

oh okay thanks

Savedyou commented 4 years ago

Untitled

This worked for me but needed a restart.

pixeljellyfish commented 4 years ago

thats what i did and it doesn't work for me

Myzumi commented 4 years ago

create a .env file and install 'dotenv' as package (npm i dotenv) and write in you main file

require('dotenv').config()

in the .env you can store variables, and if you upload it to a github don't forget to add the .env in the .gitignore

.env file conten be like: CLIENT_ID=YOUSUPERSECRETCLIENTID CLIENT_SECRET=YOUSUPERSECRETTOKEN

pixeljellyfish commented 4 years ago

ok thank you