-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ts
More file actions
85 lines (76 loc) · 2.44 KB
/
test.ts
File metadata and controls
85 lines (76 loc) · 2.44 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//SAMPLE TEST CODE
import { initializeApp } from 'firebase/app';
import { DeviceFlowUI } from "./dist/FirebaseDeviceFlow";
import * as fs from 'fs';
// ------ OPTION 1: Create config objects directly ------
// const app = firebase.initializeApp({
// // Firebase App Config Object
// });
// const ui = new DeviceFlowUI(app, {
// //FDF Config Object
// /**
// * Example FDF Config Object:
// *
// * - Provider is a key, one of Google, GitHub, etc.
// * - Scopes are a list of scope strings (defined by the provider's API)
// * - Client ID and client secret are provided by the providers
// *
// * {
// * Provider1 : {
// * scopes : ['scope'],
// * clientid : 'clientid',
// * clientsecret : 'clientsecret'
// * },
// * Provider2 : ...
// * }
// */
// });
// ------ OPTION 2: Set up your app to use a .env file for the two configuration objects ------
if(fs.existsSync('.env')){
const config = require('dotenv').config();
if (config.error) {
throw config.error
} else {
console.log('Environment variable file found!')
}
} else {
console.log('Environment variable file not found. Assuming variables are set.')
}
const app = initializeApp({
apiKey: process.env.FIREBASE_APIKEY,
authDomain: process.env.FIREBASE_AUTHDOMAIN,
databaseURL: process.env.FIREBASE_DATABASEURL,
projectId: process.env.FIREBASE_PROJECTID,
storageBucket: process.env.FIREBASE_STORAGEBUCKET,
messagingSenderId: process.env.FIREBASE_MESSAGINGSENDERID,
appId: process.env.FIREBASE_APPID,
measurementId: process.env.FIREBASE_MEASUREMENTID
});
const ui = new DeviceFlowUI(app, {
Google : {
scopes : process.env.GOOGLE_SCOPES?.split(' '),
clientid : process.env.GOOGLE_CLIENTID,
clientsecret : process.env.GOOGLE_CLIENTSECRET
},
GitHub : {
scopes : process.env.GITHUB_SCOPES?.split(' '),
clientid : process.env.GITHUB_CLIENTID,
clientsecret : process.env.GITHUB_CLIENTSECRET
}
});
// FOR EVALUATION: Unit tests
ui.authTests().then(()=>{
// FOR PRODUCTION: Sign in functionality
ui.signIn().then(user=>{
if(user.displayName){
console.log("Welcome, "+user.displayName+"!");
} else {
console.log("Welcome!");
}
// Do what you want here!
}, err=>{
console.log(err);
});
}).catch(reason=>{
console.log(reason)
});