forked from hplush/slowreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpasswords.ts
More file actions
31 lines (29 loc) · 802 Bytes
/
passwords.ts
File metadata and controls
31 lines (29 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import type { BaseServer } from '@logux/server'
import { deletePassword, setPassword } from '@slowreader/api'
import { hash } from 'argon2'
import { eq } from 'drizzle-orm'
import { db, users } from '../db/index.ts'
export default (server: BaseServer): void => {
server.type(setPassword, {
access(ctx, action) {
return action.userId ? ctx.isServer : true
},
async process(ctx, action) {
await db
.update(users)
.set({ passwordHash: await hash(action.password) })
.where(eq(users.id, action.userId ?? ctx.userId))
}
})
server.type(deletePassword, {
access() {
return true
},
async process(ctx) {
await db
.update(users)
.set({ passwordHash: null })
.where(eq(users.id, ctx.userId))
}
})
}