Code Monkey home page Code Monkey logo

discord-login's Introduction

Nuxt 3 with Discord OAuth

GitHub deployments

This is a simple example of how to use Discord OAuth with Nuxt 3.

It uses Pinia, and implements a simple auth store and server side sessions so that the user can refresh the page and still be logged in.

Check out the live demo.

Deploy with Vercel Deploy with Heroku

Configuration

You will need to create a Discord application and add the following redirect URIs, the first is for the page based callback, and the second for the server based callback:

http://localhost:3030/callback  
http://localhost:3030/api/v1/auth/discord/callback

You will need to generate the URLs for both of these, and add them to the .env file. NUXT_PUBLIC_DISCORD_LOGIN_URL is the URL for the page based callback, and NUXT_PUBLIC_DISCORD_LOGIN_URL_SERVER is the URL for the server based callback.

You will also need to create a .env file with the following variables:

NUXT_PUBLIC_DISCORD_APPLICATION_ID=...
NUXT_PUBLIC_DISCORD_PUBLIC_KEY=...
NUXT_PUBLIC_DISCORD_CLIENT_ID=...
NUXT_PUBLIC_DISCORD_LOGIN_URL_SERVER=...
NUXT_PUBLIC_DISCORD_LOGIN_URL=https://discord.com/api/oauth2/authorize?...
NUXT_PUBLIC_DISCORD_CALLBACK_URI=http://localhost...
NUXT_DISCORD_CLIENT_SECRET=...

NUXT_PUBLIC_DISCORD_LOGIN_URL_SERVER is the login URL used if you want to use server endpoint instead of client endpoint.

You can find the values for the first 5 variables in the Discord Developer Portal.

The NUXT_DISCORD_CLIENT_SECRET is the client secret for your Discord application.

You will need to set theNUXT_PUBLIC_DISCORD_LOGIN_URL_SERVER,NUXT_PUBLIC_DISCORD_LOGIN_URL and NUXT_PUBLIC_DISCORD_CALLBACK_URI variables to the correct values for your application, for production and development respectively.

Setup

Make sure to install the dependencies, I use bun for this project, but you can use npm, pnpm, or yarn.

bun install

Development Server

Start the development server on http://localhost:3030:

bun run dev

Production

Build the application for production:

bun run build

Locally preview production build:

bun run preview

Check out the deployment documentation for more information.

discord-login's People

Contributors

l422y avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.