session livekit token
Some checks failed
Deploy / deploy (push) Has been cancelled

This commit is contained in:
2026-09-05 14:46:17 +06:00
parent 95931c6976
commit a26343e99d
8 changed files with 173 additions and 25 deletions

View File

@@ -3,6 +3,7 @@ import bcrypt from 'bcrypt'
import { z } from 'zod'
import { auth } from '../auth/lucia.ts'
import prisma from '../prisma/client.ts'
import { createSessionLivekitToken, getSessionLivekitToken } from '../utils/livekit.ts'
export default function (fastify: FastifyInstance) {
fastify.post('/register', async (req, reply) => {
@@ -22,7 +23,9 @@ export default function (fastify: FastifyInstance) {
},
})
const session = await auth.createSession(user.id, {})
const session = await auth.createSession(user.id, {
livekitToken: await createSessionLivekitToken(user),
})
const cookie = auth.createSessionCookie(session.id)
reply.setCookie(cookie.name, cookie.value, cookie.attributes)
@@ -67,7 +70,9 @@ export default function (fastify: FastifyInstance) {
return reply.code(404).send({ error: 'Incorrect username or password' })
}
const session = await auth.createSession(user.id, {})
const session = await auth.createSession(user.id, {
livekitToken: await createSessionLivekitToken(user),
})
const cookie = auth.createSessionCookie(session.id)
reply.setCookie(cookie.name, cookie.value, cookie.attributes)
@@ -92,11 +97,22 @@ export default function (fastify: FastifyInstance) {
})
fastify.get('/me', async (req, reply) => {
if (req.user) {
return req.user
if (!req.user || !req.session) {
reply.code(401).send(false)
return
}
reply.code(401).send(false)
try {
return {
...req.user,
livekitToken: await getSessionLivekitToken(req.user, req.session),
}
}
catch (err) {
fastify.log.error(err)
reply.code(500).send({ error: err.message })
}
})
fastify.post('/logout', async (req, reply) => {