Using Direct third party authentication to REST API on Heroku

I have built an API on Heroku that uses node.js and a PostgreSQL database. I’ve got an endpoint for logging in: https://my-url.herokuapp.com/api/auth/login which returns:

res.status(200).json({ message: Welcome ${user.username}!, token });

if successful, or

res.status(200).json({ message: “Not logged in” })

if unsuccessful.

I’ve added Direct third party authentication to my AppGyver app which creates a login page for username and password with a Log in button. The logic on the button has a component tap which displays a dialog, sets an app variable and then dismisses the initial view.

I guess I need to replace the dialog with my logic to send the username and password to my endpoint and then check the return value. Can I get some guidance on how this is done, please?

Hi! I think a good place to start would be to check out this tutorial by @SeanHoots [ Tutorial ] How to setup 3rd-Party Authentication (using Bubble as an example backend) Even though it uses a different API you could see the basics on how to build a custom auth from that.

Basically, you could just use HTTP Request Flow function to send username and password to your API and based on the response you’d either show an alert and allow user to try logging in again or you’d save the token (to app variable and possible to storage) and dismiss the initial view.

Thanks, looking at it now and it seems to help me along the way.

When I test the Login API direct integration I get a Status OK showing but I’m not getting anything showing in the call response. I have set the Response schema to have a message and a token which is what my API returns but nothing displays. Should these not be displayed?

If the schemas match and API response works as it should, you should be able to bind the response to be visible of you want it to be. You can try to use Alert Flow function and bind its title or message to the response, e.g. outputs["HTTP request"].resBodyRaw or ENCODE_JSON(outputs["Get record"].record) to see what the response actually holds.

But in real use the key is that you should be able to bind the individual properties to the variables or other places you need those in.

I’ve tried displaying the results of the http request in an alert and I’m not getting anything displayed. Here are the full details:

I’ve got a node.js API on Heroku, when I use PostMan to send a POST request with this as the body:

{
    "username": "fred",
    "password": "mypassword"
}

I get this returned:

{
    "message": "Welcome fred!",
    "token": "the full token which I've replaced with this"
}

When I do this in Appgyver:

image

and then run the test, I get this returned:

If I send in an invalid username or password I get the appropriate json being returned and can display the message returned in an alert.

So is this something wrong with my API? or is it something with how I am telling AppGyver to read the response?

It seems that your response doesn’t have any Response key path so you should remove the text “response” from that field. Now the configuration assumes your response would look like this:

response : {
    "message": "Welcome fred!",
    "token": "the full token which I've replaced with this"
}

The key path removes the “unnecessary” levels of schema from the result to make it easier for you to access the response data and if you have many fields on root level, it specifies the needed one. So as your data isn’t nested you don’t need it.

I think this should fix your issue, but let me know if it doesn’t help.

Thanks! that looks like it has done the trick.