B4J Question FireStore Rest API Help

walterf25

Expert
Licensed User
Longtime User
Hi everyone, I'm currently working on an ABMaterial web app and I am using this library (class) found here so far I have used this in a few other projects and I like it very much as it makes it simple to leverage the use of firestore sign in, sign up and firestore database functions.

I am seeing an issue at the moment that I can't figure out why it's happening, If I run the project on my local pc everything works as expected, but when I run the project from a VPS I see an issue when I try to use the sendEmailVerification function.

The problem I am seeing is that I get the following error:
[CODE lang="json" title="Response Error"]}
ResponseError. Reason: , Response: {
"error": {
"code": 400,
"message": "MISSING_REQ_TYPE",
"errors": [
{
"message": "MISSING_REQ_TYPE",
"domain": "global",
"reason": "invalid"
}
]
}
}[/CODE]

From looking at the error I know it's easy to assume that I am missing the REQ_TYPE, but I am not, the following is the code that gets executed when running the sendEmailVerification function.
[CODE lang="b4x" title="sendEmailVerification"]'Send email verification
'https://firebase.google.com/docs/reference/rest/auth#section-send-email-verification
'requestType - The type of confirmation code to send. Should always be "VERIFY_EMAIL".
'idToken - The Firebase ID token of the user to verify.
Public Sub sendEmailVerification(requestType As String,idToken As String) As ResumableSub

Dim url As String = $"https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=${API_KEY}"$
'''https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=[API_KEY]
Dim json As JSONGenerator
json.Initialize(CreateMap("requestType":requestType,"idToken":idToken))
Log("emailverification json: " & json.ToPrettyString(3))
Dim j As HttpJob : j.Initialize("",Me)
'''j.PostString(url,json.ToString)
j.PostBytes(url, json.ToString.GetBytes("UTF-8"))
j.GetRequest.SetContentType("application/json")
j.GetRequest.SetHeader("requestType", requestType)

Wait For (j) JobDone(j As HttpJob)
Return GenerateResult(j)
#If Documentation
requestType - The type of confirmation code to send. Should always be "VERIFY_EMAIL".
idToken - The Firebase ID token of the user to verify.
#End If

End Sub[/CODE]

And here's the code where that function is called:
[CODE lang="b4x" title="sendEmailVerification call"]wait for (authRest.sendEmailVerification("VERIFY_EMAIL", ABMShared.tokenID)) Complete(Result As Map)[/CODE]

This is the Json string being sent, as you can also see from there the "VERIFY_EMAIL" requestType is included on there.
[CODE lang="json" title="Json String for request"]emailverification json: {
"requestType": "VERIFY_EMAIL",
"idToken": "eyJhbGciOiJSUzI1NiIs....
}[/CODE]

As you can see the REQ_TYPE is being passed as the first parameter as "VERIFY_EMAIL" which according to the documentation that's what it should be when using this function.

As I mentioned this works fine when I run the web app on my local PC, but I receive the above error when running it from my VPS.

Does anyone have any idea or experienced with this library and that can provide some feedback?

Walter
 
I've never used firestone to handle user registrations, but I suspect it's probably a matter of setting the correct domain to handle.
I prefer to handle the registration, login, password reminder, etc myself. This is not difficult to do.
 
Upvote 0
I've never used firestone to handle user registrations, but I suspect it's probably a matter of setting the correct domain to handle.
I prefer to handle the registration, login, password reminder, etc myself. This is not difficult to do.
Thanks, the reason I decided to use firestore is because it makes it easier to manage users, sign up users, authenticate etc. I have thought about creating classes to handle everything myself but why re-invent the wheel.

Walter
 
Upvote 0
Hello,

This post is not about Firestore, but i think there is something in common.

I think that not all B4X-B4J libs/classes works with ABMaterial.
Thanks for the reference @yiankos1 I read through your post and I really hope is not the case, the firestore class I'm using should work just fine as it's not using any third party libraries, it uses only the JOKHTTPUtil library, essentially it makes http GET and POST requests to the firestore REST API, so theoretically it should work just the way it does in my local machine.

I have one theory, since you can add your own domain to the email template that firestore uses to send the emailverification to the users, it takes up to 48 hours for firestore to verify the domain, I'm waiting one more day to see if that's the case, if I'm correct then I think everything should work just fine. But I may be wrong, I'll keep you guys updated.

Thanks for all your feedback guys.

Walter
 
Upvote 0
Not sure why you use PostByte instead of PostString.
This was just me trying different things, I am actually using PostString.
 
Upvote 0
Back
Top