Supabase Twilio Phone Auth - react-native

I am building a react native app using Supabase with phone auth on Android emulator.
I have set my twilio and Supabase up, but when I call supabase.auth.signUp(), it does not send a OTP to my phone number.
This is my code:
async function signInWithPhoneNumber() {
let { data, error } = await supabase.auth.signUp(
{ phone: '+61 xxx xxx xxx',
password: 'some-password' }) setConfirm(data);
console.log(data)
if (error) {
console.log('error')
return } }
And I just have a button that calls this function. The 'xxx xxx xxx' is a placeholder for my actual number. I tried using the provided Twilio phone number as well but to no success. My twilio account is working well, as i was able to send a message from Twilio to my real phone. And I correctly put in the phone auth details for Supabase.
My log for the 'data' gives me: {"session": null, "user": null}
And if i was to log the actual error, it gives me: [AuthRetryableFetchError: Network request failed]
Anyone know the issue?
Thanks!

I don't think you can use phone authentication with password: only OTP. Have you tried the following:
await supabase.auth.signInWithOtp({
phone: '+61xxxxxxxxx',
})
await supabase.auth.verifyOtp({
phone: '+61xxxxxxxxx',
token: 'xxxxxx',
type: 'sms'
})
see also:
https://supabase.com/docs/reference/javascript/auth-signinwithotp
https://supabase.com/docs/reference/javascript/auth-verifyotp

Related

Give web app permanent control of google email

I recently got a domain from Google Domain and it provides professional emails for the domain. So, I made a support#domain email to send and receive emails. Right now, I built a web app that will use this email to send email-verification to new users who sign up.
I got the code working, however, I used OAuth2.0 from Google to allow the web app to sign into the support email. This causes the Access token to expire and forces me to into my .env file and replace BOTH tokens. How tedious! If I were to publish this web app, I can't just go into my heroku vars and replace the tokens every hour. Thats extremely impractical.
I looked into service accounts by google, but they seem to STILL need OAuth anyways as a 3 legged OAuth. As I am using Express.js, I wanted to know if there was a way to set the tokens and be done with it permanently. Essentially giving the web app permanent control of the google account. What do I do? And what do I use? All advice is greatly appreciated.
Code for sending email verification:
const nodemailer = require("nodemailer")
const dotenv = require("dotenv")
const {generateVerifyToken} = require("./auth")
const { print } = require("#AlecRuin/color-logger")
dotenv.config()
let transporter = nodemailer.createTransport({
service:"gmail",
auth: {
type: 'OAuth2',
user: process.env.EMAIL,
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
refreshToken: process.env.REFRESH_TOKEN,
accessToken: process.env.ACCESS_TOKEN
}
})
module.exports= async function(email){
try {
let mailOptions={
from: "support#domain.us",
to:email,
subject:"Verify your email",
text:`
Thank you for signing up with redacted!!
To verify your email (and make sure you're not some kind of annoying bot), simply follow this link:
${process.env.NODE_ENV === "production"?"www.redacted.com":"localhost:3001"}/api/user/verify/?token=${generateVerifyToken(email)}
`
}
print("sending email",new Error,{isClient:false})
transporter.sendMail(mailOptions,(err,data)=>{
if (err){
console.error(err);
return err
}else{
print("Email sent!",new Error,{isClient:false})
return true
}
})
} catch (error) {
print(error,new Error, {isClient:true,severity:4})
return error
}
}

Can't receive SMS message with Twilio trial account

I have a small project (Express) using a Twilio trial account to send an SMS message to my phone number. But when I use my own message to replace the example string, I can't receive the SMS anymore.
This is what I tried:
Verified my own number, so the Twilio phone number can send SMS messages to my own phone number.
Verified the token and sid are the live credentials, not the testing one.
Check the SMS Log, and the status of all messages are sent. But again, I don't receive anything.
Used postman to verify the route if it is working properly. And yes, it did.
This is my code for the route to call the function to send the SMS
router.post("/contacts/sms", authorization, async (req, res) => {
try {
const { phone, message } = req.body;
**sendSms(phone, message);**
res.status(201).send({
message:
"Account created successfully, kindly check your phone to activate your account!",
});
} catch (error) {
res.status(500).send("Server error");
}
});
This is the SMS function
require("dotenv").config();
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const sendSms = (phone, message) => {
const client = require("twilio")(accountSid, authToken);
client.messages
.create({
body: message,
from: process.env.TWILIO_PHONE_NUMBER,
to: phone,
})
.then((message) => console.log(message.sid));
};
module.exports = sendSms;
I have answered a similar question, you might wanna have a look at that
https://stackoverflow.com/a/71912348/17503984
The problem might be since your Twilio phone number and the number you are sending are from different nationalities, communication problems arise due to the international SMS service

nodejs robinhood api login

I am trying to login to the robinhood API, I turned 2fa and sms off in the app but am still getting an error does this look correct below or is robinhood just slow at updating when 2fa is turned off.
var credentials = {
username: '*****',
password: '*****'
};
var Robinhood = require('robinhood')(credentials, function(){
console.log(Robinhood.auth_token());
// <authenticated alphanumeric token>
})
the error
Error: token not found {"statusCode":400,"body":{"detail":"Request blocked, challenge type required.","accept_challenge_types":{"sms":"SMS"}},"headers":{"date":"Mon, 24 May 2021 22:44:07 GMT","content-type":"application/json","content-length":"93","connection":"close","server":"openresty","allow":"POST, OPTIONS","x-robinhood-api-version":"0.0.0","content-security-policy":"default-src 'none'","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","x-xss-protection":"1; mode=block","access-control-allow-origin":"https://robinhood.com","vary":"Origin","trace-uuid":"56ccb9cc-8bca-4dbd-be6f-4a6d86171354"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"api.robinhood.com","port":443,"hostname":"api.robinhood.com","hash":null,"search":null,"query":null,"pathname":"/oauth2/token/","path":"/oauth2/token/","href":"https://api.robinhood.com/oauth2/token/"},"method":"POST","headers":{"Host":"api.robinhood.com","Accept":"*/*","Accept-Encoding":"gzip, deflate","Referer":"https://robinhood.com/","Origin":"https://robinhood.com","content-type":"application/x-www-form-urlencoded","content-length":214}}}
Robinhood recently required 2fa to be enabeld if using the api. It is mentioned in the detail of the request body.
"detail":"Request blocked, challenge type required.","accept_challenge_types":{"sms":"SMS"}}
Go ahead and turn it on and then you can access the api with this snippet
let Robinhood = require('robinhood')(credentials, function(data) {
if (data && data.mfa_required) {
var mfa_code = ""; //Notice this is blank.
Robinhood.set_mfa_code(mfa_code, () => {
console.log(Robinhood.auth_token());
Robinhood.positions((error, response, body) => {
console.log(body);
})
})
}
})
Once you make a request you'll get an error, but the 2fa challenge will be sent to whatever you set your account with. Once you received the 2fa code, set the mfa_code and re-run the snippet. Once you ran the snippet again with a valid 2fa code, then you've successfully logged in. Copy the authorization token and you can use that without the need of going through 2fa again for i believe 24 hrs

How to Handle push notification when sent to multiple device but some them are failed

I want to send fcm push notifications to android and ios app. I am using this code to send
let message = {
registration_ids: firebaseId, // this is the array of tokens
collapse_key: 'something',
data: {
type: data.type,
title: data.title,
body : data.body,
notificationId: something
},
};
fcm.send(message, (err, response) => {
if (err) {
console.log(err);
resolve(false);
} else {
console.log("Notification Android Sent Successfully");
console.log(response);
}
});
Now what I want if some notifications are failed then I want to send them SMS. but I got a response like this form the fcm server in case of success or failure.
Notification Android Sent Successfully
{"multicast_id":7535512435227354255,"success":2,"failure":1,"canonical_ids":0,"results":[{"message_id":"0:1610622370449056%d0bd483c86f03759"},{"message_id":"0:1610622370449058%d0bd483c86f03759"},{"error":"InvalidRegistration"}]}
now how will I know which device did not get the notification as we can see there 1 failure from 3 device
so i can send SMS to that device
The results in the response you get contains the result for each token, in the same order in which you specified them,
So in your example, the message was successfully sent to the first two tokens, while the third token was unknown. You'll want to remove that last token from your database to prevent trying to send messages to it in the future.

Invited friends aren't getting apprequest invitations, Facebook API-SDK

Hi I'm sending app requests invitations and my facebook friends aren't getting nothing. I'm using the Facebook API is loading perfectly in my page I can connect , retrieve the basic fb data, email and stream publish ... and right now I'm trying to send invitations from the same page using this code
PIGSKIN.inviteFBfriendsToGroup = function () {
//console.log("invite FB friends");
FB.ui({
method: 'apprequests',
message: 'Invita a tus amigos a unirse al PigSkin Caliente',
display: "iframe"
},function (response) {
console.log("Response", response);
var friends = response.to;
if (friends.length > 0) {
FB.ui({
method: 'apprequests',
message: 'Te invito a unirte al PigSkin de Caliente',
to: friends.join(","),
link: location.href,
new_style_message: true
}, function (response) {
console.log("Response here ", response);
});
}
});
};
I'm opening the apprequest dialog to select friends and invite them ,then I confirm the invitation request ..
and it responds me this
the response object seems correct I guess ... but checking with my fb friends they didn't receive any invitation ... is this a facebook issue ? or I'm doing something wrong
Sorry I forgot to post my login:
FB.login(function (response) {
if (response.status === 'connected') {
PIGSKIN.FBconnect(); //Don't worry about this function ...
}
},{scope:"email,publish_stream,publish_actions"});
Thanks
Facebook documentation
https://developers.facebook.com/docs/reference/dialogs/requests/
your FB.ui function is working perfectly, i've replicate the documentation example with your FB.ui code and the result was successful... Maybe it's facebook, or maybe the permissions on Caliente's fb-page... can't tell... Good luck.