React Gin Blog (13/19): JWT authentication

Authentication is one of the most important part of almost every web application. We must ensure that every user can create, read, update and delete only data for which it’s authorized. For that purpose we will use JWT (JSON Web Token). Fortunately, there are various Golang modules specialized for this. One that will be usedContinue reading “React Gin Blog (13/19): JWT authentication”

React Gin Blog (12/19): Logging

Logging is also pretty important part of most web applications because we usually want to know what requests are coming in, and what’s more important, whether there are any unexpected errors. So, as you may have guessed, this section will introduce logging and i will show you how to setup logging, and how to separateContinue reading “React Gin Blog (12/19): Logging”

React Gin Blog (11/19): Deploy and stop scripts

Now that we moved our configuration to ENV, we need to source .env every time we restart our machine or shell session, which can become a bit tedious. To make our lives easier, we will create bash scripts for starting and stopping server. While at it, we will also separate deploy for dev and prodContinue reading “React Gin Blog (11/19): Deploy and stop scripts”

React Gin Blog (10/19): Server configuration

Currently we have hardcoded values for server address and port. Same goes for database options required for connecting to our database. That is obviously not a great solution, so let’s extract this configuration to ENV variables and add logic to read values from there. First we will create new directory internal/conf/ and there we willContinue reading “React Gin Blog (10/19): Server configuration”

React Gin Blog (9/19): Hashing password

In last section we have created users table in our database, but we are currently storing user’s password in plain text. This is something we should never do, and instead we need to store hashed password with random salt. For that we will use golang/crypto library. First we need to expand our User structure: ThereContinue reading “React Gin Blog (9/19): Hashing password”

React Gin Blog (8/19): Migrations

With database created, we also need to create tables in which our data will be store. And best way to do that is using migrations. We will be using go-pg/migrations module. On GitHub page you can find basic installation and usage guide, and we will use that. Let’s start by creating new directory migrations/ insideContinue reading “React Gin Blog (8/19): Migrations”

React Gin Blog (7/19): Connecting with database

So far our backend is working very well. We can create user and login, but as soon we restart our server, that user data is lost, since it is saved only in memory while app is running. Of course that’s not realistic case and we want to save all user data even if server isContinue reading “React Gin Blog (7/19): Connecting with database”

React Gin Blog (6/19): Form validations

As we saw in previous section, our handlers are working as expected when we pass valid data. But what about not valid data? Or missing data? Let’s test this. First, let’s remove (or just comment) Password: passwordValue from our submitHandler() inside of assets/src/components/Auth/AuthForm.js. This way, our backend will send only Username, without Password. Let’s nowContinue reading “React Gin Blog (6/19): Form validations”

React Gin Blog (5/19): Adding user

We are making simple blog, so first thing we have to do is to implement some way for users to create account and log in. For now, we will just make simple struct User that will be stored in memory. Latter we will connect our application with a database so we can store our dataContinue reading “React Gin Blog (5/19): Adding user”

React Gin Blog (4/19): Structure project directories

It’s always good practice to separate your code based on what every part is doing, so it’s easier to find relevant part later on, so we will do just that before going further. In root project directory we will create new directories cmd/rgb/ and we will move our main.go file there. That will be entryContinue reading “React Gin Blog (4/19): Structure project directories”