deemixer/server/src/routes/api/post/loginEmail.ts
RemixDev c8f02b310d Added --singleuser flag to server
replaces the old --serverwide-arl flag of deemix-pyweb
it's always off on the gui
2022-03-09 12:34:18 +01:00

31 lines
813 B
TypeScript

import { ApiHandler } from '../../../types'
import { getAccessToken, getArlFromAccessToken } from '../../../app'
import { saveLoginCredentials } from '../../../helpers/loginStorage'
const path = '/loginEmail'
const handler: ApiHandler['handler'] = async (req, res) => {
const isSingleUser = req.app.get('isSingleUser')
const { email, password } = req.body
let accessToken = req.body.accessToken
if (!accessToken) {
accessToken = await getAccessToken(email, password)
if (accessToken === 'undefined') accessToken = undefined
}
let arl
if (accessToken) arl = await getArlFromAccessToken(accessToken)
if (isSingleUser && accessToken)
saveLoginCredentials({
accessToken,
arl: arl || null
})
res.send({ accessToken, arl })
}
const apiHandler = { path, handler }
export default apiHandler