Skip to content

Commit

Permalink
fix: 修正 signOut 方法默认重定向为 nuxt.config.ts 中 pages.login 路由
Browse files Browse the repository at this point in the history
  • Loading branch information
gxmari007 committed Jan 6, 2024
1 parent 889bb8f commit 63aa688
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 26 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export default defineNuxtConfig({
})
```

## 许可

[MIT](/LICENSE)

<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/@roshan-labs/auth/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-version-href]: https://npmjs.com/package/@roshan-labs/auth
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
],
"scripts": {
"prepack": "nuxt-module-build build",
"dev:local": "nuxi dev playground",
"dev:local": "nuxi dev playground-local",
"dev:refresh": "nuxi dev playground-refresh",
"dev:build": "nuxi build playground",
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground && nuxi prepare playground-refresh",
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground-local && nuxi prepare playground-refresh",
"release": "npm run lint && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
"lint": "eslint .",
"test": "vitest run",
Expand Down Expand Up @@ -73,4 +73,4 @@
"vitest": "^1.1.3",
"zod": "^3.22.4"
}
}
}
4 changes: 3 additions & 1 deletion playground-local/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default defineNuxtConfig({
type: 'local',
endpoints: {
signIn: { path: '/login', method: 'post' },
signOut: false,
getSession: { path: '/user', method: 'get' },
},
pages: {
Expand All @@ -20,6 +19,9 @@ export default defineNuxtConfig({
isEnabled: true,
permissionPointer: '/permission',
},
token: {
// maxAgeInSeconds: 60,
},
},
globalAppMiddleware: true,
},
Expand Down
17 changes: 0 additions & 17 deletions playground-local/pages/about.vue

This file was deleted.

5 changes: 5 additions & 0 deletions playground-local/pages/forbidden.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>
<h1>Forbidden</h1>
</div>
</template>
8 changes: 4 additions & 4 deletions playground-local/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<div>
<h1>Home</h1>
<div>
<div>
<nuxt-link to="/about">About</nuxt-link>
</div>
<ul>
<li><nuxt-link to="/no-permission">No permission</nuxt-link></li>
</ul>
<div>
<button @click="logout">Sign Out</button>
</div>
<div>
<button>Add</button>
<button v-permission="['edit']">Edit</button>
<button v-permission="['add', 'delete']">Delete</button>
<button v-permission="['no-permissions']">Can't see me</button>
<button v-permission="['no-permission']">Can't see me</button>
</div>
</div>
</div>
Expand Down
13 changes: 13 additions & 0 deletions playground-local/pages/no-permission.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<div>
<h1>No permission</h1>
</div>
</template>

<script lang="ts" setup>
definePageMeta({
auth: {
permission: [''],
},
})
</script>
2 changes: 1 addition & 1 deletion src/runtime/composables/local/use-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const signOut: SignOut<any> = async (signOutOptions = {}, fetchOptions) => {
const { redirect = true, callbackUrl, external } = signOutOptions

if (redirect) {
await navigateTo(callbackUrl ?? '/', { external })
await navigateTo(callbackUrl ?? config.pages.login, { external })
}

return response
Expand Down

0 comments on commit 63aa688

Please sign in to comment.