Skip to content

Commit

Permalink
fix: auth
Browse files Browse the repository at this point in the history
  • Loading branch information
TinsFox committed Oct 31, 2024
1 parent bba50a4 commit 26758fa
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 260 deletions.
1 change: 1 addition & 0 deletions .dev.vars.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[vars]
SECRET_KEY = ""
COOKIE_KEY = "token"
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"name": "mock-service",
"type": "module",
"packageManager": "pnpm@9.10.0",
"packageManager": "pnpm@9.12.3",
"scripts": {
"dev": "wrangler dev src/index.ts",
"deploy": "prisma generate && wrangler deploy --minify src/index.ts",
"deploy": "wrangler deploy --minify src/index.ts",
"test": "vitest",
"prepare": "prisma generate"
},
"dependencies": {
"@faker-js/faker": "^9.1.0",
"@hono/swagger-ui": "^0.4.1",
"@prisma/adapter-d1": "^5.19.1",
"@prisma/client": "5.19.1",
"@prisma/extension-accelerate": "^1.1.0",
"@prisma/adapter-d1": "^5.21.1",
"@prisma/client": "^5.21.1",
"@prisma/extension-accelerate": "^1.2.1",
"bcryptjs": "^2.4.3",
"hono": "^4.6.2",
"@faker-js/faker": "^9.0.1"
"hono": "^4.6.8"
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.5.6",
"@cloudflare/workers-types": "^4.20240919.0",
"@cloudflare/vitest-pool-workers": "^0.5.23",
"@cloudflare/workers-types": "^4.20241022.0",
"@types/bcryptjs": "^2.4.6",
"@types/node": "^22.5.5",
"prisma": "^5.19.1",
"@types/node": "^22.8.5",
"prisma": "^5.21.1",
"ts-node": "^10.9.2",
"typescript": "^5.6.2",
"vitest": "^2.1.1",
"wrangler": "^3.78.6"
"typescript": "^5.6.3",
"vitest": "^2.1.4",
"wrangler": "^3.84.0"
}
}
447 changes: 232 additions & 215 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/middleware/auth-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { jwt } from "hono/jwt"
import { Context, Next } from "hono"
const authWhiteList = ["/api/auth/login", "/api/auth/register"]

const authWhiteList = ["/api/auth/login", "/api/auth/register", "/api/seed"]

export const authMiddleware = (c: Context, next: Next) => {
if (authWhiteList.includes(c.req.path)) {
Expand Down
5 changes: 2 additions & 3 deletions src/module/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,14 @@ async function seedAlbum(prisma: PrismaClient) {
data: FakerAlbumList,
})
}

seedRouter.get("/", async (c) => {
console.log("🌱 Seeding...")
console.time(`🌱 Database has been seeded`)
const adapter = new PrismaD1(c.env.DB)
const prisma = new PrismaClient({ adapter })
console.time("🧹 Cleaned up the database...")
const albums = await prisma.album.findMany()
console.log(albums)
await cleanupDb(prisma)
// await cleanupDb(prisma)

console.timeEnd("🧹 Cleaned up the database...")

Expand Down
2 changes: 1 addition & 1 deletion src/module/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ userRouter.get("/", async (c) => {

userRouter.get("/info", async (c) => {
const payload = c.get("jwtPayload")
console.log("payload: ", payload.sub)
console.log("payload: ", payload)
const prisma = getPrisma(c.env.DB)
const user = await prisma.user.findUnique({
omit: {
Expand Down
5 changes: 1 addition & 4 deletions src/types/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import type { TimingVariables } from "hono/timing"
import type { RequestIdVariables } from "hono/request-id"
import type { JwtVariables } from "hono/jwt"

export type Bindings = {
DB: D1Database
SECRET_KEY: string
COOKIE_KEY: string
}

export type JwtVariables = {
jwtPayload: IPayload
}

export interface IPayload {
sub: string
role: string
Expand Down
22 changes: 0 additions & 22 deletions wrangler.toml.example

This file was deleted.

0 comments on commit 26758fa

Please sign in to comment.