forked from tregismoreira/firebase-auth-generate-token
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (46 loc) · 1.21 KB
/
index.js
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
38
39
40
41
42
43
44
45
46
47
48
49
const { initializeApp } = require('firebase/app');
const {getAuth,signInWithEmailAndPassword} = require("firebase/auth");
const prompt = require('prompt');
require('dotenv').config();
// Initialize Firebase App.
initializeApp({
apiKey: process.env.FIREBASE_API_KEY,
authDomain: process.env.FIREBASE_AUTH_DOMAIN,
projectId: process.env.FIREBASE_PROJECT_ID,
});
// Start and setup prompt.
prompt.start();
prompt.get(
{
properties: {
email: {
required: true,
},
password: {
required: true,
hidden: true,
},
},
},
function(err, result) {
let email = result.email;
let password = result.password;
// Authenticate user using email and password.
var auth = getAuth();
signInWithEmailAndPassword(auth,email, password)
.then(async function(response) {
let idtoken = await auth.currentUser.getIdToken();
console.log(idtoken);
// Get the access token of the authenticated user.
// firebase
// .auth()
// .currentUser.getIdToken()
// .then(token => {
// console.log(token);
// });
})
.catch(error => {
console.error(error);
});
},
);