Files
score-backend/routes/user.ts
ethan.chen e511ab9db6 feat: enhance deployment process and server configuration
- Updated `deno.json` to allow environment variable access in the start task.
- Added `deploy.sh` script for building and deploying the application to a remote server.
- Modified `main.ts` to retrieve the `AUTH_SECRET` and `PORT` from environment variables.
- Created `my-score.service` for managing the Deno service with systemd.
- Cleaned up `user.ts` by removing unnecessary console logs.
2025-06-19 16:28:50 +08:00

40 lines
935 B
TypeScript

/*
* @Date: 2025-06-11 17:57:58
* @LastEditors: 陈子健
* @LastEditTime: 2025-06-16 11:17:09
* @FilePath: /my-score/honoback/routes/user.ts
*/
import { Hono } from 'hono'
import { sign } from 'hono/jwt'
import type { JwtVariables } from 'hono/jwt'
import { db } from '../db/index.ts'
const user = new Hono<{ Variables: JwtVariables }>()
const AUTH_SECRET = 'it-is-a-secret'
// 登录路由
user.post('/login', async (c) => {
const { username, password } = await c.req.json()
// 从数据库验证用户
const user = db.prepare('SELECT * FROM users WHERE username = ? AND password = ?')
.get(username, password)
if (user) {
const token = await sign({ username: user.username }, AUTH_SECRET)
return c.json({
code: 200,
data: { token },
message: '登录成功'
})
}
return c.json({
code: 401,
message: '用户名或密码错误'
}, 401)
})
export default user