-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.js
More file actions
21 lines (17 loc) · 696 Bytes
/
users.js
File metadata and controls
21 lines (17 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// user/auth related stuff
const database = require('./database');
const admin = require('firebase-admin');
// for use with jsonapis - logs a user in
async function login({u, h})
{
if (!u || u.length == 0 || !h || h.length == 0)
return {error:'Missing args'};
let user = await database.GetDoc(database.firestore.collection('User').where('email', '==', u));
if (!user || user.passwordHash != h)
return {error:'Unknown user or incorrect password'};
// seems legit, create an auth token for Firebase
let token = await admin.auth().createCustomToken(user.id, {roles:user.roles || {}});
return {error:'', token};
}
login.anon = true;
exports.login = login;