aboutsummaryrefslogtreecommitdiffhomepage
path: root/pkgs/server/src/routes/auth.test.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-12-03 05:45:41 +0900
committernsfisis <nsfisis@gmail.com>2025-12-04 23:26:30 +0900
commit0763153865e2157e0d06c946993dd8b235b06c83 (patch)
tree8da68ed2e9c16bf121d59eae02e19b99f7f11fdc /pkgs/server/src/routes/auth.test.ts
parentf44390286378860b535e37ad045cb374a07aff5c (diff)
downloadkioku-0763153865e2157e0d06c946993dd8b235b06c83.tar.gz
kioku-0763153865e2157e0d06c946993dd8b235b06c83.tar.zst
kioku-0763153865e2157e0d06c946993dd8b235b06c83.zip
feat(auth): add refresh token endpoint
Implement refresh token functionality for authentication: - Add refresh_tokens table to database schema with user reference - Generate migration for the new table - Login endpoint now returns both access token and refresh token - Add POST /api/auth/refresh endpoint with token rotation - Refresh tokens are hashed (SHA256) before storage for security - Tokens expire after 7 days, access tokens after 15 minutes - Update tests to cover new functionality 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'pkgs/server/src/routes/auth.test.ts')
-rw-r--r--pkgs/server/src/routes/auth.test.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/pkgs/server/src/routes/auth.test.ts b/pkgs/server/src/routes/auth.test.ts
index 1dfba46..28bd558 100644
--- a/pkgs/server/src/routes/auth.test.ts
+++ b/pkgs/server/src/routes/auth.test.ts
@@ -43,6 +43,13 @@ vi.mock("../db", () => {
username: "username",
createdAt: "created_at",
},
+ refreshTokens: {
+ id: "id",
+ userId: "user_id",
+ tokenHash: "token_hash",
+ expiresAt: "expires_at",
+ createdAt: "created_at",
+ },
};
});
@@ -67,6 +74,7 @@ interface RegisterResponse {
interface LoginResponse {
accessToken?: string;
+ refreshToken?: string;
user?: {
id: string;
username: string;
@@ -188,6 +196,11 @@ describe("POST /login", () => {
}),
} as unknown as ReturnType<typeof db.select>);
+ // Mock the insert call for refresh token
+ vi.mocked(db.insert).mockReturnValueOnce({
+ values: vi.fn().mockResolvedValue(undefined),
+ } as unknown as ReturnType<typeof db.insert>);
+
const res = await app.request("/api/auth/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
@@ -201,6 +214,8 @@ describe("POST /login", () => {
const body = (await res.json()) as LoginResponse;
expect(body.accessToken).toBeDefined();
expect(typeof body.accessToken).toBe("string");
+ expect(body.refreshToken).toBeDefined();
+ expect(typeof body.refreshToken).toBe("string");
expect(body.user).toEqual({
id: "user-uuid-123",
username: "testuser",