-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
510f720
commit fc4d25c
Showing
2 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// const client = require("../../../../index")(process.env.SID, process.env.AUTH, { | ||
// isPostgres: true, | ||
// connectionURI: "postgres://student:ilovetesting@localhost/twoauthtests" | ||
// }); | ||
|
||
// // client.create("ian", "+17604207520"); | ||
|
||
// client | ||
// .send("ian") | ||
// .then(res => console.log(res)) | ||
// .catch(err => console.log(err)); | ||
// // describe("Tests for Postgres Send", () => { | ||
|
||
// // }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,42 @@ | ||
module.exports = function(userID, phone) { | ||
module.exports = function(userID) { | ||
const { pgConnect, client } = this; | ||
return new Promise((resolve, reject) => { | ||
this.pgConnect() | ||
pgConnect() | ||
.then(({ database, done }) => { | ||
// pgClient.query... blah blah logic | ||
//invoke done before your resolve this promise | ||
done(); | ||
const query = "SELECT * FROM twoauthusers WHERE userID=$1"; | ||
const values = [String(userID)]; | ||
database.query(query, values, (err, res) => { | ||
if (err) reject(err); | ||
const { sid, phone } = res.rows[0]; | ||
if (!sid) | ||
reject(new Error("SID Error: No SID exists for this user.")); | ||
if (!phone) | ||
reject( | ||
new Error( | ||
"Phone Number Error: No phone number exists for this user." | ||
) | ||
); | ||
//invoke done before your resolve this promise | ||
client.verify | ||
.services(sid) | ||
.verifications.create({ | ||
to: phone, | ||
channel: "sms" | ||
}) | ||
.then(verification => { | ||
done(); | ||
resolve(verification); | ||
}) | ||
.catch(err => { | ||
done(); | ||
reject(err); | ||
}); | ||
}); | ||
}) | ||
.catch((err, done) => { | ||
//invoke done before you reject | ||
.catch(err => { | ||
done(); | ||
reject(err); | ||
//"userID Error: This userID has not been created yet." | ||
}); | ||
}); | ||
}; |