Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthController ¶
func NewAuthController ¶
func NewAuthController(s *server.Server) *AuthController
func (*AuthController) Delete ¶
func (c *AuthController) Delete(req *fiber.Ctx) error
Delete handles the deletion of a user by retrieving the user data from the JWT token in the "auth" cookie, deleting the user from the database, and returning a JSON response with the status code fiber.StatusOK.
Parameters:
- req: a pointer to a fiber.Ctx object representing the HTTP request context.
Returns:
- error: an error object if there was an issue decoding the JWT token, finding the user, or deleting the user from the database. Otherwise, nil.
func (*AuthController) Login ¶
func (c *AuthController) Login(req *fiber.Ctx) error
Login handles the login request by parsing the request body, finding the user by email, comparing the password, generating a JWT token, setting the "auth" cookie, and returning a JSON response with the status code fiber.StatusOK and the token.
Parameters:
- req: a pointer to a fiber.Ctx object representing the HTTP request context.
Returns:
- error: an error if there was an issue parsing the request, finding the user, comparing the password, generating the JWT token, setting the cookie, or creating the JSON response.
func (*AuthController) Logout ¶
func (c *AuthController) Logout(req *fiber.Ctx) error
Logout handles the logout request by clearing the "auth" cookie and returning a JSON response with the status code fiber.StatusOK.
Parameters:
- req: a pointer to a fiber.Ctx object representing the HTTP request context.
Returns:
- error: an error if there was a problem setting the cookie or creating the JSON response.
func (*AuthController) Register ¶
func (c *AuthController) Register(ctx *fiber.Ctx) error
Register handles the registration request by parsing the request body, finding the user role, creating a new user with the provided information, and returning a JSON response with the user data.
Parameters:
- ctx: a pointer to a fiber.Ctx object representing the HTTP request context.
Returns:
- error: an error if there was an issue parsing the request, finding the user role, creating the user, or returning the JSON response. Otherwise, nil.
func (*AuthController) User ¶
func (c *AuthController) User(req *fiber.Ctx) error
User handles the user request by retrieving the "auth" cookie, decoding the JWT token, finding the user in the database, and returning the user data in a JSON response.
Parameters:
- req: a pointer to a fiber.Ctx object representing the HTTP request.
Returns:
- error: an error object if there was an issue decoding the JWT token, finding the user, or returning the JSON response. Otherwise, nil.