Generalize Authentication
Closed this issue · 0 comments
In the authController.go
are two function used to check if an authenticated admin or student sent the request, depending on the API call.
Make a single function that handles this authentication. The function will take two parameters and return a boolean and string.
func AuthenticateRequest(c *fiber.Ctx, userType int) (verified bool, cid string)
userType indicating if it is a student, teacher, or admin we need to check is authenticated,
cid is the custom ID of the user returned if successfully authenticated to use in some API calls.
In order for this generalized authentication to work, we can search the databases cid collection.
This however will not detect if the cid is related to the correct userType. So it is required to add a
parentType into the idModel.go
to be able to compare if the user has the correct authentication.