🎉 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 | 端點 | /login | 否 |
authHome | 端點 | /home | 否 |
cookieKey | 字串 | XSRF-TOKEN | 否 |
cookieHeader | 字串 | X-XSRF-TOKEN | 否 |
tokenStorageKey | 字串 | API-TOKEN | 否 |
endpoints.csrf | 端點 | /sanctum/csrf-cookie | 否 |
endpoints.login | 端點 | /login | 否 |
endpoints.logout | 端點 | /logout | 否 |
endpoints.user | 端點 | /user | 否 |
endpoints.tfa.enable | 端點 | /user/two-factor-authentication | 否 |
endpoints.tfa.disable | 端點 | /user/two-factor-authentication | 否 |
endpoints.tfa.code | 端點 | /user/two-factor-qr-code | 否 |
endpoints.tfa.confirm | 端點 | /user/confirmed-two-factor-authentication | 否 |
endpoints.tfa.recoveryCode | 端點 | /user/two-factor-recovery-codes | 否 |
endpoints.tfa.challenge | 端點 | /two-factor-challenge | 否 |
endpoints.register | 端點 | /register | 否 |
endpoints.resetPassword | 端點 | /forgot-password | 否 |
endpoints.updatePassword | 端點 | /reset-password | 否 |
endpoints.confirmPassword | 端點 | /user/confirm-password | 否 |
endpoints.resendEmailVerificationLink | 端點 | /email/verification-notification | 否 |
intendedRedirect | 布林值 | true | 否 |
features.registration | 布林值 | true | 否 |
features.resetPasswords | 布林值 | true | 否 |
features.emailVerification | 布林值 | true | 否 |
features.updateProfileInformation | 布林值 | true | 否 |
features.updatePasswords | 布林值 | true | 否 |
features.twoFactorAuthentication | 布林值 | true | 否 |
tfaRoute | 端點 | /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 上建立此儲存庫的 fork。
- 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 或聯絡此儲存庫的維護者。
感謝您的貢獻!您的努力受到高度讚賞。 🙌