Skip to content

Commit

Permalink
JWT Auth for Web
Browse files Browse the repository at this point in the history
  • Loading branch information
Yousef Wadi committed Feb 20, 2022
1 parent a3a060b commit 2a7693a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Servers/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func HTTP_Start(cq *Structs.S_GOQ) {
SigningKey: []byte("crimsonQ"),
}))

app.Get("/checkToken", checkToken)

for k, v := range Commands {
if v.HTTP_Method == Defs.HTTP_GET {
route := "/api/" + strings.ReplaceAll(k, ".", "/")
Expand All @@ -79,6 +81,13 @@ func HTTP_Start(cq *Structs.S_GOQ) {
app.Listen(":" + viper.GetString("HTTP.port"))
}

func checkToken(c *fiber.Ctx) error {
user := c.Locals("user").(*jwt.Token)
claims := user.Claims.(jwt.MapClaims)
name := claims["name"].(string)
return c.SendString("Welcome " + name)
}

func login(c *fiber.Ctx) error {
bodyData := PostAuthBody{}
if err := c.BodyParser(&bodyData); err != nil {
Expand Down

0 comments on commit 2a7693a

Please sign in to comment.