-
Notifications
You must be signed in to change notification settings - Fork 17
/
first_auth.js
44 lines (39 loc) · 1.21 KB
/
first_auth.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
const fs = require("fs")
const path = require("path")
const Spotify = require("./Spotify.js")
let file = path.resolve(__dirname, "spotify.config.json")
let configurations = []
if (fs.existsSync(file)) {
let configurators = JSON.parse(fs.readFileSync(file))
configurators.forEach((configurator) => {
configurations.push(configurator)
})
}
else return console.log("[SPOTIFY] Error: please configure your spotify.config.json file")
async function authorize(configuration) {
return await new Spotify(configuration, true, true).authFlow()
.catch((error) => {
console.error("[SPOTIFY - " + configuration.USERNAME + "] Error in authentication:")
throw error
})
}
async function authorizations(configurations) {
for (const configuration of configurations) {
await authorize(configuration)
.then((result) => {
console.log(result)
})
.catch((error) => {
console.error("[SPOTIFY - " + configuration.USERNAME + "]", error)
throw error
})
}
return true
}
authorizations(configurations)
.then((result) => {
console.log("[SPOTIFY] Authorization process finished")
})
.catch((error) => {
console.error("[SPOTIFY] Authorization process failed")
})