Skip to content

Commit

Permalink
Merge pull request #119 from NOctu1412/main
Browse files Browse the repository at this point in the history
Fallback to vonage if firebase doesn't work
  • Loading branch information
s-alad authored Jun 22, 2024
2 parents 4062940 + 56d3694 commit 07c8806
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion client/pages/api/otp/fire/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
console.log(error.response);
console.log(error.response.data)
console.log(error.response.data.error)
res.status(400).json({ status: "error" });
res.status(400).json({ status: "error", errorData: error.response.data.error });
}
)

Expand Down
2 changes: 1 addition & 1 deletion client/pages/api/otp/fire/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
error_message = error.toString();
}
console.log(error_message);
res.status(400).json({ error: error_message });
res.status(400).json({ error: error_message, full_error: error });
}

}
7 changes: 4 additions & 3 deletions client/pages/api/otp/vonage/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
console.log('---------------------')

res.status(200).json({
token: access_token,
refresh_token: access_refresh_token,
bereal_access_token: access_token,
firebase_refresh_token: firebase_refresh_token,
firebase_id_token: firebase_token,
token_type: access_token_type,
expiration: access_expiration,
expiration: firebase_expiration,
uid: uid,
is_new_user: is_new_user
});
Expand Down
20 changes: 11 additions & 9 deletions client/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function Home() {
}

function helpme() {
setHelp("Failed with Vonage login provider, re-trying to login with Firebase...");
setHelp("Failed with Firebase login provider, re-trying to login with Vonage...");
setTimeout(() => {setHelp("");}, 4000);
}

Expand All @@ -54,8 +54,9 @@ export default function Home() {
let response = axios.request(options).then(
async (response) => {
console.log(response.data);
localStorage.setItem("token", response.data.token);
localStorage.setItem("refresh_token", response.data.refresh_token);
localStorage.setItem("token", response.data.bereal_access_token);
localStorage.setItem("firebase_refresh_token", response.data.firebase_refresh_token);
localStorage.setItem("firebase_id_token", response.data.firebase_id_token)
localStorage.setItem("expiration", response.data.expiration)
localStorage.setItem("uid", response.data.uid);
localStorage.setItem("is_new_user", response.data.is_new_user);
Expand All @@ -79,14 +80,14 @@ export default function Home() {
data: body,
}

let response = axios.request(options).then(
axios.request(options).then(
(response) => {
let rvonageid = response.data.vonageRequestId;
console.log(response.data);
setVonageid(rvonageid);
setRequestedOtp(true);
}
).catch((error) => {failure(JSON.stringify(error.response.data.error)); helpme(); requestOTPFirebase(number);})
).catch((error) => {failure("VONAGE REQUEST ERROR: " + JSON.stringify(error.response.data.error));})
}

async function verifyOTPFirebase(otp: string) {
Expand Down Expand Up @@ -115,11 +116,10 @@ export default function Home() {
}
).catch((error) => {
if (error.response) {
failure(error.response.data.error)
failure("FIREBASE VERIFY ERROR: " + error.response.data.error)
}else {
failure("unknown error, please try re-logging in")
failure("FIREBASE VERIFY ERROR: " + "unknown error, please try re-logging in")
}

})
}

Expand All @@ -145,7 +145,9 @@ export default function Home() {
}
).catch(
(error) => {
console.log(error.response);
failure("FIREBASE OTP REQUEST ERROR:" + JSON.stringify(error));
helpme();
requestOTPVonage(number);
}
)
}
Expand Down

0 comments on commit 07c8806

Please sign in to comment.