Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

reactjs - How to implement firebase's signInWithPhoneNumber in express?

I wish to implement signInWithPhoneNumber() on the backend. That is, Get the phone number and recaptcha on the front, let the backend handle the request to firebase, send the confirmation code from the front with the confirmationResult to the backend and verify there.

How do I go about sending the recaptcha to my express backend? signInWithPhoneNumbers requires RecaptchaVerifier as a second argument, which returns a promise. I can't send it as is, is there a work around for this?

question from:https://stackoverflow.com/questions/66068952/how-to-implement-firebases-signinwithphonenumber-in-express

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Firebase is a technology meant to be used as a backend and not behind another backend. The documentation of firebase clearly indicates that the javascript sdk is to be used for web front end (https://firebase.google.com/docs/web/setup).

Whereas express js is a backend. Given a design choice of abstracting firebase behind the api, I would suggest you revisit the design choice. As in mentioned in another comment this appears to be a XY problem (http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). The api you are trying to use is meant for a web based browser or a mobile frontend. You may end up with a hacky implementation in trying to go with the design choice or have to change the way you authenticate to use firebase Auth on frontend and pass a token after Auth to the backend. Have a look at these links

https://dev.to/emeka/securing-your-express-node-js-api-with-firebase-auth-4b5f https://fireship.io/snippets/express-middleware-auth-token-firebase/

There is another option of using a custom implementation of authentication backend to generate token and use that token to sign in to firebase. That would however beat the purpose of the firebase Auth. I would recommend it only if you already have a existing backend and are adding firebase for different features of firebase. Please consider this link if that matters to you.

https://firebase.google.com/docs/auth/web/custom-auth


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...