mirror of
https://github.com/vitalityAI/therapist.git
synced 2025-04-08 05:40:17 -04:00
24 lines
619 B
JavaScript
24 lines
619 B
JavaScript
import { PrismaClient } from '@prisma/client';
|
|
import {db} from './db.js'
|
|
|
|
export const authorize = async (req, res, admin=false) => {
|
|
let authorization = null
|
|
if(!authorization) authorization = req.headers.authorization
|
|
if(!authorization && req.cookies.auth) {
|
|
const auth = JSON.parse(req.cookies.auth)
|
|
if(auth) authorization = `Bearer ${auth.access_token}`
|
|
}
|
|
const token = authorization.replace("Bearer ", "")
|
|
const webSession = await db.webSession.findUnique({
|
|
where: {
|
|
token: token
|
|
},
|
|
})
|
|
|
|
const authorized = webSession != null
|
|
|
|
return {
|
|
authorized,
|
|
webSession
|
|
}
|
|
} |