Skip to content

Commit

Permalink
go fmt post merge
Browse files Browse the repository at this point in the history
  • Loading branch information
CamPlume1 committed Sep 19, 2024
1 parent 500bb77 commit f88ff3c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
3 changes: 1 addition & 2 deletions backend/cmd/server/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"log"
"github.com/GenerateNU/nightlife/internal/config"
"github.com/GenerateNU/nightlife/internal/db"
"github.com/GenerateNU/nightlife/internal/middleware"
"github.com/GenerateNU/nightlife/internal/router"
"github.com/gofiber/fiber/v2"
"log"
)

func main() {
Expand All @@ -26,7 +26,6 @@ func main() {
//Create App
app := fiber.New()


//Initialize Middleware
middleware.UseMiddleware(app)

Expand Down
8 changes: 1 addition & 7 deletions backend/internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func parseJWTToken(token string, hmacSecret []byte) (email string, err error) {
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}

fmt.Println(hmacSecret)
return hmacSecret, nil
})

Expand All @@ -39,21 +38,16 @@ func parseJWTToken(token string, hmacSecret []byte) (email string, err error) {
func Protected(cfg *config.Config) fiber.Handler {

return func(ctx *fiber.Ctx) error {
fmt.Print("Successfully called auth middleware")

token := ctx.Get("Authorization", "")
token = strings.TrimPrefix(token, "Bearer ")

if token == "" {
return ctx.Status(400).JSON(fiber.Map{"code": "unauthorized, token not found"})
}

fmt.Println("Secret" + cfg.JWTToken)
email, err := parseJWTToken(token, []byte(cfg.JWTToken))
_, err := parseJWTToken(token, []byte(cfg.JWTToken))

if err != nil {
fmt.Println(email)
fmt.Println(err)
return ctx.Status(400).JSON(fiber.Map{"code": "unauthorized, error parsing token"})
}
return ctx.Next()
Expand Down
5 changes: 2 additions & 3 deletions backend/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Config struct {
SupabaseURL string
SupabaseKey string
DatabaseURL string
JWTToken string
JWTToken string
}

// loads configuration from the specified .env file path
Expand Down Expand Up @@ -53,7 +53,6 @@ func LoadConfig(envPath string) (*Config, error) {
}

jwtToken := os.Getenv("SUPABASE_JWT_TOKEN")
fmt.Println("SUPABASE SECRET FOUND: " + jwtToken)
if databaseURL == "" {
log.Fatalf("JWT Token is not set in .env")
return nil, fmt.Errorf("JWT Token is not set in .env")
Expand All @@ -63,7 +62,7 @@ func LoadConfig(envPath string) (*Config, error) {
SupabaseURL: supabaseURL,
SupabaseKey: supabaseKey,
DatabaseURL: databaseURL,
JWTToken: jwtToken,
JWTToken: jwtToken,
}

return config, nil
Expand Down

0 comments on commit f88ff3c

Please sign in to comment.