Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SebbeJohansson/e0ef18ca6aac7aca1ce91684f319418b to your computer and use it in GitHub Desktop.
Save SebbeJohansson/e0ef18ca6aac7aca1ce91684f319418b to your computer and use it in GitHub Desktop.
Nuxt3 Discord Authentication Example
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
modules: [
'@nuxt-alt/auth', // https://www.npmjs.com/package/@nuxt-alt/auth
'@pinia/nuxt',
],
auth: {
redirect: {
login: '/auth/login',
logout: '/auth/logout',
home: '/',
callback: '/auth/callback', // dont forget to add this path as a redirect in Discord Developer Portal
},
strategies: {
discord: { // https://auth.nuxtjs.org/providers/discord
clientId: '{{clientid}}',
clientSecret: '{{clientsecret}}',
},
},
},
});
<script setup lang="ts">
console.log("callback");
</script>
<template>
<div>
<NuxtWelcome />
</div>
</template>
<script setup lang="ts">
console.log(useAuth().loginWith('discord'));
</script>
<template>
<div>
<NuxtWelcome />
</div>
</template>
<script setup lang="ts">
console.log('logout');
useAuth().logout();
</script>
<template>
<div>
<NuxtWelcome />
</div>
</template>
<script setup>
console.log(useAuth().user);
const { user } = useAuth();
</script>
<template>
<div>
{{ user }}
<NuxtLink to="/auth/login">
Log in with discord
</NuxtLink>
<NuxtWelcome />
</div>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment