Simple authentication example with JWT
How to
- Clone the repo
go mod tidy
to install dependencies- Create .envrc file for your environment variables
export DSN=postgres://<db_user>:<db_pass>@<db_host>/<db_name>
export JWT_SECRET=<random words>
make start
to start the application
API Reference
GET http://localhost:9000/
_response_
{
"msg": "index route"
}
POST http://localhost:9000/register
_request_
{
"username" : "user one",
"email": "[email protected]",
"password" : "userone123"
}
_response_
{
"msg": "user successfully registered"
}
POST http://localhost:9000/login
_request_
{
"email": "[email protected]",
"password" : "userone123"
}
_response_
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyJpc3MiOiJqd3QtZXhhbXBsZSIsInN1YiI6InVzZXJvbmVAZ21haWwuY29tIiwiZXhwIjoxNjU2OTQ3MTUyLCJpYXQiOjE2NTY5NDM1NTJ9.
vHSTfTB1ICllFc4-J2lGFJT7J_Dwodse1WEFYn1JC1M"
}
GET http://localhost:9000/private
Header | Description |
---|---|
Authorization |
Your JWT Token |
_response_
{
"msg": "private route",
"user": "[email protected]"
}