feat: add user authentication system

- User model (users table) with bcrypt password hashing
- JWT-based login API (POST /api/auth/login, GET /api/auth/me)
- Default admin account (admin/admin123) auto-created on startup
- Login page with centered dark-themed login card
- Route guards + Axios interceptors for token management
- Login page renders without sidebar (standalone layout)
- Gunicorn --preload to avoid worker DDL race condition
This commit is contained in:
2026-06-14 23:22:53 +08:00
parent 521cf0269c
commit cd41e59afc
14 changed files with 430 additions and 11 deletions
+19 -6
View File
@@ -5,14 +5,16 @@ import TaskDetail from '../views/TaskDetail.vue'
import Agents from '../views/Agents.vue'
import Alerts from '../views/Alerts.vue'
import Settings from '../views/Settings.vue'
import Login from '../views/Login.vue'
const routes = [
{ path: '/', component: Dashboard },
{ path: '/tasks', component: Tasks },
{ path: '/tasks/:id', component: TaskDetail, name: 'TaskDetail' },
{ path: '/agents', component: Agents },
{ path: '/alerts', component: Alerts },
{ path: '/settings', component: Settings },
{ path: '/login', component: Login, meta: { public: true } },
{ path: '/', component: Dashboard, meta: { requiresAuth: true } },
{ path: '/tasks', component: Tasks, meta: { requiresAuth: true } },
{ path: '/tasks/:id', component: TaskDetail, name: 'TaskDetail', meta: { requiresAuth: true } },
{ path: '/agents', component: Agents, meta: { requiresAuth: true } },
{ path: '/alerts', component: Alerts, meta: { requiresAuth: true } },
{ path: '/settings', component: Settings, meta: { requiresAuth: true } },
]
const router = createRouter({
@@ -20,4 +22,15 @@ const router = createRouter({
routes,
})
router.beforeEach((to, from, next) => {
const token = localStorage.getItem('token')
if (to.meta.requiresAuth && !token) {
next('/login')
} else if (to.path === '/login' && token) {
next('/')
} else {
next()
}
})
export default router