Last active
July 20, 2023 08:39
-
-
Save NetLancer/cdab1330659cbe209a89f5654f9e7559 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getCurrentUser = async (session) => { | |
if (!session || typeof session.id !== 'number') { | |
throw new Error('Invalid session') | |
} | |
const qResult = await db.user.findUnique({ | |
where: { id: session.id }, | |
select: { id: true, email: true, roles: true }, | |
}) | |
if (qResult?.roles?.includes(",")) { // roles string includes commas | |
const arr = [] | |
qResult.roles.split(',').map(r => { | |
r.length && (arr.push(r.trim())) // treat if accidental trailing comma .. | |
}) | |
qResult.roles = arr // now we have a neat array of values | |
} | |
return qResult | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment