r/AskProgramming • u/CorrectJacket2106 • Aug 31 '26
Architecture Lost in website architecture
So, I am in like high school, so sorry if the question is really dumb in advance. So let's get into it!
I have this problem where I am making a website, and I am working on the login feature of the website. I was planning to do something like check if you have an account in Discord either way, I have a massive problem because the Discord thingy needs my token and I heard sharing your bot token is like a really bad thing. So I went to AI (I mean, I had no other choice at that time), and AI told me to do something like this:
frontend (javascript) ---> discord OAuth url thingy(idk what it is) ---> discord redirects to firebase cloud function (idk what it is again) ---> cloud function thingy handles bot token and discord api checks ---> cloud function writes verification result straight to firestore database
Now, I am a beginner, so I don't know what all of this means (maybe the first 2, but anything else, nah). I also want to store data when the user logs in, something like user = {general info, clients={}}and AI is telling me to do it in the frontend?? I have heard all day long from everywhere that you should use the backend, not the frontend. So really lost, and any help would help!
also for the database i was planning to use firebase or whatever it is called since i heard it was the best
1
u/KingofGamesYami Aug 31 '26
Do you actually need a bot token? If you literally just want to sign in with discord, you should request a much less privileged scope(s) for the token. For example, the
identifyscope will allow you to get some information from discord about the user, but won't allow you to control their discord account.1
u/Necessary-Green-8391 Aug 31 '26
The AI flow is correct and keeps your token safe on the server. Store the user data in Firestore through that same Cloud Function after verification completes so the frontend never writes to the database directly
1
u/PLBjt Aug 31 '26
The reason everyone says "use the backend" is that the OAuth code-for-token exchange needs your client secret, and anything in frontend JavaScript is readable by every visitor, so that step has to happen on a server you control. Shape it as: browser sends the user to the Discord authorize URL, Discord redirects back to your backend with a code, your backend swaps the code for a token using the secret, looks up or creates the user row, and hands the browser its own session cookie. After that your frontend never touches Discord tokens, it just talks to your API with that session. The check I use is "could someone read this value in devtools" — if yes it can't be a secret, which is also why storing users straight from the frontend into Firebase gets risky unless you lean hard on its security rules. One process plus one database is plenty here; keep it boring until something actually hurts.