Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
nextjs-discord-bot (with oauth2)
Overview
Accessing the designated root url (
/
) will require authentication with Discord. Upon authorizing, the user will beredirected back to the root url (with additional user details displayed)
Replication
OAuth2 URLs
Generate your own OAuth2 redirect URI with every additional scope needed
(
discord.com/applications/CLIENT_ID/oauth2
)/api/auth/discord/redirect
Add these urls (development and production) to
config.ts
:Discord endpoints
POST
request to Discord's oauth token endpoint(
discord.com/api/v10/oauth2/token
)access_token
from the data given is used to receive the Discord user's details by making aGET
request tothe
discord.com/api/v10users/@me
endpoint:Vercel Postgres / Prisma
I've implemented a prisma table which will store the encrypted access & refresh token from the user data. This can be used later, but for now has minimal impact on the application.
Prisma is used to store the
User
model:Quickstart
Create a postgres database on your vercel dashboard
Retreive the environment variables locally:
Generate the prisma client:
Create the table(s) in your database based on your prisma schema:
build
script withinpackage.json
has been altered to support the prisma database in production:Encryption
crypto-js is used to encrypt the
access_token
&refresh_token
before storing into theUser
model.ENCRYPTION_KEY
environment variable (make sure to also add this to your vercel project environment variables)Cookies & JWT
jsonwebtoken & cookie are used for signing & serializing the cookie for the user session.
JWT_SECRET
environment variable (make sure to also add this to your vercel project environment variables)Updates
.env.local.example
has been updated to include:config.ts
has been made to include necesssary authentication URLs