This Xano backend provides authentication (without the Firebase setup) and allows you to upload images and comments. The authentication works by having a login form that returns an auth-token that Bravo propagates to other requests.
We have to change the stock functionality to make it work with the image upload in Bravo.
1.Signup with Xano
2.At how do you want to start — choose “Photo sharing social media platform”
1.Click on API on the left hand side
2.In photo sharing click on View 27 Endpoints to get this (record the Base Request URL highlighted in red below, you will need it later in the Bravo API Binding steps):
3.click on the /photo endpoint
4. In inputs click on image
5.Click on + next to inputs
6.Click on + next to function stack
7.Click on Add record from photo block
The photo API should now look like this:
Now we need to get an auth-token to help do the setup in Bravo.
8.Click the blue Run & Debug button (above). This will open the debug pane:
If you click on the cog in blue, it will bring up a list of users, just click on one and Xano will log that user in and give you an auth-token (starting ‘eyJ…’), You need to copy and paste this auth-token somewhere as we will need it in the Bravo API step.
Your design should look like this in Bravo:
We need to add all the api requests that we need from Xano in Bravo:
1.Click on Data Library in Bravo on the left hand side
2.Click on New Collection
3.Click on ‘Custom API’ and Name it Foodgram with Xano
4.Click on the + button next to Requests to add a new request for each of the following 6 requests (NB the <Base Request URL> comes from step (B)2 above.
Name: Signup
Type: POST
Request URL: <Base Request URL>/auth/signup
Headers : None
Parameters:
Key = email, Value = test@test.com
Key = password, Value = passw0rdBody:
{
"email" : "${email}",
"name" : "${email}",
"handle" : "${email}",
"password" : "${password}"
}
Once you have setup the Signup Request, hit the blue send button for this request to add that user to Xano so we can setup the other requests.
Name: Login
Type: POST
Request URL: <Base Request URL>/auth/login
Headers : None
Parameters:
Key = email, Value = test@test.com
Key = password, Value = passw0rd
Body:
{
"email" : "${email}",
"password" : "${password}"
}
Once you have inputted the above hit the blue send button for this request to get sample data to allow the received data to be setup for this request.
Make sure the .data.authToken field is ticked and then in the Selected Data tab change the field’s name to auth-token. We can reference this name as a variable in other requests to allow the request to pass authentication.
Name: Add photo
Type: POST
Request URL: <Base Request URL>/photo
Headers : Key = Authorization, Value = Bearer ${auth-token}
Parameters: None
Body:
{
"caption" : "${caption}",
"image_url" : "${image_url}",
"tags" : ""
}
For this step we will need the auth token form step (B) 8, to enable us to highlight the data we need.
Name: Get all photos
Type: GET
Request URL: <Base Request URL>/photo
Headers : Key = Authorization, Value = Bearer ${auth-token}
Parameters: Key = auth-token, Value = <Auth Token from step (B)8>
Body: None
Once you have inputted the above hit the blue send button for this request to get sample data to allow the received data to be setup for this request.
Make sure the following fields are ticked in the Received data pane , .data.items[], .data.items[].id, .data.items[].caption, .data.items[].image.url, .data.items[].user.handle. Then change the name of the .data.items[].id field to photo_id. (NB this name photo_id needs to be consistent, i.e. not photo-id throughout the queries as its is used by the app to reference the particular photo for comments etc),
Name: Add comment
Type: POST
Request URL: <Base Request URL>/comment
Headers : Key = Authorization, Value = Bearer ${auth-token}
Parameters:
Key = auth-token, Value = <Auth Token from step (B)8>
Key = comment, Value = Test Comment
Key = photo_id, Value = 1
Body:
{
"comment" : "${comment}",
"photo_id" : "${photo_id}"
}
Once you have inputted the above hit the blue send button for this request to create a test comment to help with the comment setup.
Name: Get photo comments
Type: GET
Request URL: <Base Request URL>/comments/${photo_id}
Headers : Key = Authorization, Value = Bearer ${auth-token}
Parameters:
Key = auth-token, Value = <Auth Token from step (B)8>
Key = photo_id, Value = 1
Body: None
Once you have inputted the above hit the blue send button for this request to get sample data to allow the received data to be setup for this request.
Make sure the following fields are ticked in the Received data pane, .data.items[], .data.items[].id, .data.items[].comment , and .data.items[].user.handle .
Now all the APIs are now setup in Bravo and we just have to connect them to the design.
Now that we have the APIs in Bravo the last step is to connect them to the app design. Go into the Foodgram with Xano app so you can see all the screens.
1.Signup
Click on the Signup screen to edit the binding for this screen, choose the Foodgram with Xano collection and then the signup request
2.Login
Click on the Login screen to edit the binding for this screen, choose the Foodgram with Xano collection and then the login request
3.Home Screen
Click on the Homescreen to edit the binding for this screen, choose the Foodgram with Xano collection and then the Get all photos request
4.New Post screen
Click on the New Post screen to edit the binding for this screen, choose the Foodgram with Xano collection and then the Add Photo request
5.Comments screen
Click on the Comments screen to edit the binding for this screen, choose the Foodgram with Xano collection and then the Get photo comments request
6.Click on the New Comment screen to edit the binding for this screen, choose the Foodgram with Xano collection and then the Add Comment request
You should now be able to test your app in Bravo Vision, signup and then login and add images and comment on them.
As you add content you can check it working by looking at the tables in Xano, or make request from the Run and debug panels for each request.
Have fun, and let us know if you get stuck.
Bravo Team