簡體   English   中英

Nuxt.js 中間件 auth 將經過身份驗證的用戶重定向到登錄頁面

[英]Nuxt js middleware auth redirect authenticated user to login page

我正在使用@nuxt/auth package 版本4.9.1

在用戶關閉瀏覽器之前一切正常,當用戶在登錄后關閉瀏覽器並返回絕對值 URL 時會出現問題,例如example.com/admin

如何解決這個問題?

中間件/admin.js

export default function ({$auth, error}) {
  if ($auth.user.type === 'admin') {
    return error('404 Not Found!')
  }
}

頁面/admin.index

<template>
  <div class="container">
    {{ $auth.user.name || $auth.user.mobile_number }}
  </div>
</template>

<script>
  export default {
    name      : "admin",
    middleware: ['auth', 'admin'],
  }
</script>

當用戶打開絕對loggedIn時,檢查中間件中的登錄。 (example.com/admin)

欲了解更多信息: auth#loggedin

演示: Nuxt-auth-demo/secure頁面需要身份驗證才能訪問。登錄后,您可以嘗試關閉瀏覽器並使用絕對路徑nuxt-auth.herokuapp.com/secure再次打開它。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM