svelte and supabase endpoints - sveltekit

For supabase and sveltekit. which is better for fetching the data.
using the stores or using endpoints?
im trying to understand why the endpoints are so important. besides lessing down on the boiler plate code for context module, what are the benefits?

Related

Secure webapp with Django and React

I'm experimenting with these 2 technologies to make a secure web app [Currently learning React (60%) and Django (<50%). This is intended to be like a medical database, so doctors and nurses enters their patients' information. They need to login obviously. I wanted to implement React-based UI (And not using the classic method to create views from django), so I've found many tutorials just like this one:
https://www.digitalocean.com/community/tutorials/build-a-to-do-application-using-django-and-react
It basically turns Django into a restAPI, and then the React frontend uses axios to retrieve data from the endpoint. Sounds not bad at all (comparing to the native method of rendering data in a webpage from Django), but the problem is that I have no idea on how to make this secure, you know, Django provides an auth system, which is pretty good and secure, I have to say, but in a project with this structure, the auth needs to be done in React, so there many questions appear:
To start with, is it a good idea to make a project of this structure? (If no, then what could be a good one)
If it's a yes, how can I protect the API so only logged in users can interact with it? (What mechanisms to ensure protection)
Yes, this is absolutely a good idea to separate the client application and the backend server application.
You can access the backend through the rest api basically with any frontend framework/app/script.
Customers are able to extend their own applications with the abilities of your backend service.
You can create multiple different frontends that use the same backend or different parts of the same backend via the rest api (multi-branding, reselling). Or you can just swap the frontend framework every second year to a new one.
It's also easier to create different automations by using the rest api.
And the list goes on.
For django rest api auth I would recommend Token Authentication which is already included in the Django REST Framework and for React use this tutorial for implementing the login and the token handling.
And don't forget to use TLS on your servers, and create API documentation. (Example)

Should you query Google Maps API directly or through your own REST API?

As the title explains I want to query Google Maps API based on a user input. Now, for the sake of clarity I've got a system in place with the frontend built in React and the backend on Java Spring. In particular, I want to perform forward geocoding whenever a user presses submit on a form to search for an address. Should I just do this natively inside the React code or create a service for it inside the Spring backend?
My thoughts would be that by chaining API calls would add unnecessary complexity but at the same time I don't feel like mixing responsibilities and making some part of the code call my own API and some other part ignore it completely.
If you make direct calls to Google Maps API from your frontend, you will expose your API key to frontend. Anyone could grab your API key and make queries to Google API outside of your application so unless you are sure that you can secure your api keys, i would suggest making api calls from your backend.

Using Firebase for hosting, Socket.io for backend and React for frontend in one project

I have a socket.io server for backend and a React app as my frontend, which are located in different project folders (If it makes a difference at all). Is there a way to publish them both into one project and make them work with each other using Firebase hosting?
I have read that some guy tried to do that and a Firebase employee said it's better to use Realtime Databases. The problem with those is asynchronous calls, which makes my project useless. Socket.io helps with keeping data in order and makes everything work as intended.
Is there a way to... refractor the code to make Firebase Functions work like a socket.io? Is it worth it?
What you're trying to do is not possible with Firebase products, in the way that you describe. Cloud Functions doesn't do any streaming of requests or responses.
As another Firebase employee, I also strongly suggest you take a look at Realtime Database, since it effectively can do streaming between two clients using its synchronization mechanism.
I have no idea what you mean by "the problem with those is asynchronous calls, which makes my project useless". Asynchronous programming is very standard these days, and for JavaScript and web development, asynchronous programming has always been the norm.

Connecting ReactJs app to SpringBoot MVC/PostgresQL backend

I am developing a React app that needs to be connected to a backend server so that the user can login using Google OAuth, and then once that access token is granted, they are able to see the rest of the app. However, I am having a difficult time understanding just how to connect the front-end app to the backend. If someone could enlighten me on this, using SpringBoot MVC and PostgreSQL, that would be great. Thanks!
You have several ways to communicate your FE(React) and your BE(SpringBoot MVC).
You can have REST endpoint on your Backend, and then try to communicate from your react application, you can use [axios][1], request or the native fetch.
Then you can just make calls to the BE, and try to read, update, delete or create information, you should read about CRUD.
The most common this days is build something like this:
(FE) <---> (BE) <---> (DB)
But I strongly recommend you to read more about:
- React SPA.
- REST, you can also read about SOAP or even GraphQL.
- CRUD.
You will found a lot of tutorials with very good examples of how to do it.
Hope this helps you to understand a little more what approach to use.

To use React, should I use nodejs (express)?

I plan to build Web application for which the structure is:
My questions are:
Is that correct structure in the commercial?
I plan that FrameWork of Frontend is express(nodejs) at first, but I try to change to django or flask because nodejs is my first use. I wonder if react can be used in this combination.
How about using firebase? You can handle authorization, store and retrieve data. I believe that it will be much easier than any other alternative.
This great article will enable you to implement authentication in few hours. Handling data is also simple, I would use redux as well...

Resources