-
user register
-
user login
-
protected routes (middleware)
-
password reset email
-
golang server
-
postgres db
Create a .env
file and change this so it works for you:
db_name = myapp
db_pass = password
db_user = postgres
db_type = postgres
db_host = localhost
db_port = 5434
jwt_secret = mysecret
database_url = postgres://postgres:password@localhost:5434
mail_server = smtp.gmail.com
mail_port = 465
mail_user = mailuser
mail_password = mailpass
If you don't want to build executable you can just go run main.go
If you have go1.12 installed:
make generate-bin
If you don't have go1.12 you can do it with docker as well:
make docker-build
bin/server
A route for registering a new user.
{
"email": "foo@bar.com",
"password": "password"
}
User login route. As a response user gets jwt token that can be used to access protected routes that requires user login.
{
"email": "foo@bar.com",
"password": "password"
}
This route can be used to send a reset password email to user, it stores a reset token in database that expires in 1h. This token is sent to user's email.
Emails are sent using smtp, it can be configured in .env
file.
Only smtp.gmail.com
has been tested so far. In order for gmail to work, less secure apps has to be enabled in gmail settings, you can read more about this here .
Url param :email string
This route can be used to check the status of a reset password token.
A link to this route can also be found in reset password email.
Url param :reset-token string
This changes the users password, using the token/link that was sent to users email.
Reset token status can be checked with endpoint /api/user/reset-psw-check/:reset-token
{
"token_reset": "<reset-token>",
"new_password": "newpassword"
}
Header:
Authorization : Bearer <token>