Last active
April 7, 2024 19:02
-
-
Save SebbeJohansson/e0ef18ca6aac7aca1ce91684f319418b to your computer and use it in GitHub Desktop.
Nuxt3 Discord Authentication Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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}}', | |
}, | |
}, | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script setup lang="ts"> | |
console.log("callback"); | |
</script> | |
<template> | |
<div> | |
<NuxtWelcome /> | |
</div> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script setup lang="ts"> | |
console.log(useAuth().loginWith('discord')); | |
</script> | |
<template> | |
<div> | |
<NuxtWelcome /> | |
</div> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script setup lang="ts"> | |
console.log('logout'); | |
useAuth().logout(); | |
</script> | |
<template> | |
<div> | |
<NuxtWelcome /> | |
</div> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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