Skip to content

Commit

Permalink
fix(auth): use middleware sparingly
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Jun 16, 2023
1 parent 0037c21 commit a2bd3b8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 0 additions & 2 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export default defineNuxtConfig({
auth: {
// TODO: Refresh token

globalAppMiddleware: { isEnabled: true },

baseURL: process.env.API_URL + '/auth',

provider: {
Expand Down
2 changes: 2 additions & 0 deletions pages/premium/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script lang="ts" setup>
definePageMeta({
middleware: 'auth',

auth: {
unauthenticatedOnly: true,
navigateAuthenticatedTo: '/premium/profile'
Expand Down
2 changes: 2 additions & 0 deletions pages/premium/profile.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script lang="ts" setup>
const { status, data, signIn, signOut } = useAuth()

definePageMeta({ middleware: 'auth' })
</script>

<template>
Expand Down
6 changes: 5 additions & 1 deletion pages/premium/sign-in.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
const { status, data, signIn, signOut } = useAuth()

definePageMeta({
middleware: 'auth',

auth: {
unauthenticatedOnly: true,
navigateAuthenticatedTo: '/premium'
Expand All @@ -13,6 +15,8 @@
<main>
<p>Sign-In:</p>
<!-- NOTE: Here we hard-coded username and password, on your own page this should probably be connected to two inputs for username + password -->
<button @click="signIn('credentials', { username: '_', password: 'TODO' })">Username and Password</button>
<button @click="signIn('credentials', { username: '_', password: '1CBCB551-F5E3485E-A66CCA18-CE943D51' })">
Username and Password
</button>
</main>
</template>

0 comments on commit a2bd3b8

Please sign in to comment.