session livekit token
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user