-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathregister.js
More file actions
executable file
·37 lines (30 loc) · 1.05 KB
/
register.js
File metadata and controls
executable file
·37 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
const comet = require('comet-js-sdk')
export default async function handler(req, res) {
const cs = new comet.CometServer({
url: process.env.COMET_URL,
username: process.env.COMET_ADMIN_USER,
password: process.env.COMET_ADMIN_PASSWORD
})
if (!req.body.username || !req.body.password) {
res.status(400).json({
error: "Expected a name and a password parameter"
})
return
}
try {
const userP = await cs.AdminAddUserP(req.body.username, req.body.password)
const userSession = await cs.AdminAccountSessionStartAsUserP(req.body.username)
userSession.SessionKey
res.status(200).json({
status: 'OK',
sessionKey: userSession.SessionKey,
url: process.env.COMET_URL,
username: req.body.username
})
} catch (e) {
res.status(500).json({
error: e.toString()
})
}
}