🎉 Nuxt Laravel Fortify 和 Sanctum 模組
此 Nuxt 模組以 SSR 友善的方式將 Nuxt 與 Laravel Fortify 和 Sanctum 無縫整合,提供豐富的身份驗證功能。透過此模組,您可以利用 Laravel Fortify 的功能,並執行基於 API Token 和 SPA Cookie 的身份驗證。
🚀 功能特色
- 註冊 📋
- 重設密碼 🔄
- 電子郵件驗證 📧
- 更新個人資料 ✏️
- 更新密碼 🔐
- 雙重驗證 🔒
🛠️ 安裝與設定
💡注意: 您需要在後端 Laravel 應用程式中安裝並設定 Laravel Fortify、Laravel Sanctum 和 fortify-sanctum 套件。fortify-sanctum 套件可輕鬆將 Laravel Fortify 的身份驗證功能與 Laravel Sanctum 整合
將 nuxt-fortify
模組新增至您的 nuxt 專案
npx nuxi@latest module add nuxt-fortify
💻 Nuxt 設定
透過安裝模組並在 nuxt.config.js
中設定,將其新增至您的 Nuxt 專案。
// nuxt.config.js
export default {
modules: [
'nuxt-fortify',
],
nuxtFortify: {
baseUrl: 'https://127.0.0.1:3000/api',
origin: 'https://127.0.0.1:3000',
authMode: 'cookie',
authHome: '/dashboard',
endpoints: {
csrf: '/sanctum/csrf-cookie',
user: '/user',
// other endpoints...
},
features: {
registration: true,
resetPasswords: true,
twoFactorAuthentication: true,
// other features...
}
// other configurations...
}
}
📜 設定檔
鍵 | 資料類型 | 預設值 | 是否必填 |
---|---|---|---|
baseUrl | 字串 | https://127.0.0.1:3000/api | 是 |
authMode | 字串 | cookie | 是 |
loginRoute | endpoint | /login | 否 |
authHome | endpoint | /home | 否 |
cookieKey | 字串 | XSRF-TOKEN | 否 |
cookieHeader | 字串 | X-XSRF-TOKEN | 否 |
tokenStorageKey | 字串 | API-TOKEN | 否 |
endpoints.csrf | endpoint | /sanctum/csrf-cookie | 否 |
endpoints.login | endpoint | /login | 否 |
endpoints.logout | endpoint | /logout | 否 |
endpoints.user | endpoint | /user | 否 |
endpoints.tfa.enable | endpoint | /user/two-factor-authentication | 否 |
endpoints.tfa.disable | endpoint | /user/two-factor-authentication | 否 |
endpoints.tfa.code | endpoint | /user/two-factor-qr-code | 否 |
endpoints.tfa.confirm | endpoint | /user/confirmed-two-factor-authentication | 否 |
endpoints.tfa.recoveryCode | endpoint | /user/two-factor-recovery-codes | 否 |
endpoints.tfa.challenge | endpoint | /two-factor-challenge | 否 |
endpoints.register | endpoint | /register | 否 |
endpoints.resetPassword | endpoint | /forgot-password | 否 |
endpoints.updatePassword | endpoint | /reset-password | 否 |
endpoints.confirmPassword | endpoint | /user/confirm-password | 否 |
endpoints.resendEmailVerificationLink | endpoint | /email/verification-notification | 否 |
intendedRedirect | 布林值 | true | 否 |
features.registration | 布林值 | true | 否 |
features.resetPasswords | 布林值 | true | 否 |
features.emailVerification | 布林值 | true | 否 |
features.updateProfileInformation | 布林值 | true | 否 |
features.updatePasswords | 布林值 | true | 否 |
features.twoFactorAuthentication | 布林值 | true | 否 |
tfaRoute | endpoint | /two-factor-authentication | 否 |
logLevel | 數字 | 1 | 否 |
origin | 字串 | https://127.0.0.1:3000 | 是 |
🌐 端點設定
端點鍵 | 路徑 | 請求方法 |
---|---|---|
csrf | /sanctum/csrf-cookie | POST |
login | /login | POST |
logout | /logout | POST |
user | /user | POST |
tfa.enable | /user/two-factor-authentication | POST |
tfa.disable | /user/two-factor-authentication | DELETE |
tfa.code | /user/two-factor-qr-code | GET |
tfa.confirm | /user/confirmed-two-factor-authentication | POST |
tfa.recoveryCode | /user/two-factor-recovery-codes | GET |
tfa.challenge | /two-factor-challenge | POST |
register | /register | POST |
resetPassword | /forgot-password | POST |
updatePassword | /reset-password | POST |
confirmPassword | /user/confirm-password | POST |
resendEmailVerificationLink | /email/verification-notification | POST |
透過遵循這些步驟和設定,您將擁有一個完全整合了 Laravel Fortify 和 Sanctum 的 Nuxt 應用程式,提供強大的身份驗證解決方案。 🚀
🤝 貢獻
我們歡迎您貢獻以增強此模組。以下是貢獻的步驟
- Fork 儲存庫:在 GitHub 上建立此儲存庫的分支。
- Clone 您的 Fork:將您 Fork 的儲存庫 Clone 到您的本地電腦。
git clone https://github.com/dev-charles15531/nuxt-forify.git cd nuxt-fortify
- 建立分支:為您的功能或錯誤修復建立一個新的分支。
git checkout -b feature-or-bugfix-name
- 進行變更:實作您的功能或錯誤修復。確保您的程式碼遵循專案的程式碼標準並通過所有測試。
- 提交變更:提交您的變更,並附上清晰簡潔的提交訊息。
git add . git commit -m "Description of the feature or fix"
- Push 到您的 Fork:將您的變更 Push 到您 Fork 的儲存庫。
git push origin feature-or-bugfix-name
- 開啟 Pull Request:向主儲存庫開啟 Pull Request。清楚描述您的變更以及它們解決的問題或功能。
📝 指南
- 遵循專案中使用的程式碼風格。
- 撰寫清晰、簡潔的提交訊息。
- 確保您的程式碼通過所有測試,且不會引入新的問題。
- 如果您的變更影響模組的使用或設定方式,請更新文件。
📧 聯絡方式
如果您有任何問題或需要協助,請隨時開啟 Issue 或聯絡此儲存庫的維護者。
感謝您的貢獻!您的努力將不勝感激。 🙌