-
Notifications
You must be signed in to change notification settings - Fork 48
/
auth_controller.go
49 lines (44 loc) · 1.09 KB
/
auth_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package controllers
import (
"github.com/gofiber/fiber/v2" //nolint:goimports
"github.com/gookit/validate"
"github.com/itsursujit/fiber-boilerplate/auth"
"github.com/itsursujit/fiber-boilerplate/config"
"github.com/itsursujit/fiber-boilerplate/models"
)
func OAuthToken(c *fiber.Ctx) error { //nolint:wsl
var login models.Login
if err := c.BodyParser(&login); err != nil {
return c.Status(401).JSON(fiber.Map{
"error": true,
"message": "Invalid Credentials",
})
}
v := validate.Struct(login)
if !v.Validate() {
return c.Status(401).JSON(fiber.Map{
"error": true,
"message": v.Errors.All(),
})
}
user, err := login.CheckLogin() //nolint:wsl
if err != nil {
return c.Status(401).JSON(fiber.Map{
"error": true,
"message": err.Error(),
})
}
token, err := auth.Login(c, user.ID, config.AuthConfig.Api_Jwt_Secret) //nolint:wsl
if err != nil {
return c.Status(401).JSON(fiber.Map{
"error": true,
"message": err.Error(),
})
}
return c.JSON(fiber.Map{
"token": token.Hash,
"expires_in": token.Expire,
})
}
func RefreshOauthToken(c *fiber.Ctx) {
}