Easy way to get an authetication system up and running in your application with Go
go get github.com/iqquee/auth
Create a .env file in your project root directory then copy the key value pairs below and assign appropraite values
DATABASE_NAME=<database name>
USER_COL=<collection name>
PORT=<port number>
SECRET_KEY=<secret key>
MongoDB_URI=<mondodb uri>
type User struct {
ID primitive.ObjectID `json:"_id" bson:"_id"`
User_id string `json:"user_id"`
First_Name string `json:"first_name"`
Last_Name string `json:"last_name"`
Email string `json:"email"`
Phone_Number int `json:"phone_number"`
Password string `json:"password"`
Token string `json:"token"`
Refresh_Token string `json:"refresh_token"`
Created_At time.Time `json:"created_at"`
Updated_At time.Time `json:"updated_at"`
}
Example code
{
r.POST("signup", auth.SignUp)
}
Using the auth package, access the SignUp method with `auth.SignUp`
type Login struct {
Email string `json:"email"`
Password string `json:"password"`
}
Example code
{
r.POST("signin", auth.SignIn)
}
Using the auth package, access the SignIn method with `auth.SignIn`
type PublicUser struct {
ID primitive.ObjectID `json:"_id" bson:"_id"`
First_Name string `json:"first_name"`
Last_Name string `json:"last_name"`
Email string `json:"email"`
Phone_Number string `json:"phone_number"`
}
email is the Key
user@something.com is the value
Example code
{
r.GET("user", user.GetPublicUser)
}
Using the auth package, access the GetPublicUser method with `user.GetPublicUser`
type PublicUser struct {
ID primitive.ObjectID `json:"_id" bson:"_id"`
First_Name string `json:"first_name"`
Last_Name string `json:"last_name"`
Email string `json:"email"`
Phone_Number string `json:"phone_number"`
}
Example code
{
r.GET("users", user.GetPublicUsers)
}
Using the auth package, access the GetPublicUsers method with `user.GetPublicUsers`
If you need a users authorization for certain parts of the application like create post and so on, this package also has another method called Authorization
token is the Key
generatedUserToken is the Value
Example code
{
r.POST("").Use(middleware.Authentication)
}
Using the auth package, access the Authentication method with `middleware.Authentication`