Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
piyush7833 committed Jun 9, 2024
1 parent b44605c commit ac53d63
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
27 changes: 15 additions & 12 deletions middlewares/auth-middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"net/http"

"github.com/gorilla/context"
"github.com/piyush7833/Chat-Api/functions"
"github.com/piyush7833/Chat-Api/helpers"
)

type ContextKey string
// type ContextKey string

const jwtContextKey = ContextKey("jwtData")
// const jwtContextKey = ContextKey("jwtData")

func AuthMiddleware(next http.Handler) http.Handler {
f := func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -25,22 +26,24 @@ func AuthMiddleware(next http.Handler) http.Handler {
return
}

// claims, ok := data.(*helpers.Claims)
// if !ok {
// helpers.Error(w, http.StatusUnauthorized, "Invalid token claims")
// return
// }
claims, ok := data.(*helpers.Claims)
if !ok {
helpers.Error(w, http.StatusUnauthorized, "Invalid token claims")
return
}

// user, err := helpers.Prisma.User.FindUnique(db.User.ID.Equals(claims.Id)).Exec(r.Context())
if err != nil {
var cols = []string{"id"}
user, error := functions.GetParticularUserById(claims.Id, cols)
if error.StatusCode != 0 {
helpers.Error(w, http.StatusUnauthorized, "Invalid token claims")
return
}

// if user == nil {
// helpers.Error(w, http.StatusUnauthorized, "Invalid token claims")
// return
// }
if user == nil {
helpers.Error(w, http.StatusUnauthorized, "Invalid token claims")
return
}
context.Set(r, "userId", data)
// ctx := context.WithValue(r.Context(), jwtContextKey, data)
// fmt.Println(ctx.Value(jwtContextKey).(*helpers.Claims), "data from middleware")
Expand Down
2 changes: 2 additions & 0 deletions test/init.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package test

import (
"fmt"
"os"

"github.com/gorilla/mux"
Expand All @@ -12,6 +13,7 @@ import (
)

func Init() error {
fmt.Println(os.Getenv("ENVIRONEMENT"), "ENVIRONEMENT")
if os.Getenv("ENVIRONEMENT") == "" || os.Getenv("ENVIRONEMENT") == "test" {
if err := godotenv.Load(".env.test"); err != nil {
return err
Expand Down

0 comments on commit ac53d63

Please sign in to comment.