Skip to content

Commit

Permalink
remove middleware (compatibility issues with ngrok)
Browse files Browse the repository at this point in the history
  • Loading branch information
capture120 committed Feb 25, 2024
1 parent 8292884 commit 4d7cbe7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
11 changes: 11 additions & 0 deletions backend/src/controllers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,14 @@ func (ac *AuthController) AuthenticateSession(c *gin.Context, client clerk.Clien

c.JSON(http.StatusOK, gin.H{"message": "Welcome " + *user.Username})
}

func (ac *AuthController) GetSession(c *gin.Context, client clerk.Client) {

claims, activeSession := clerk.SessionFromContext(c)

if !activeSession {
c.JSON(http.StatusOK, gin.H{"message": "No active session"})
return
}
c.JSON(http.StatusOK, gin.H{"Session ID": claims.SessionID})
}
9 changes: 4 additions & 5 deletions backend/src/routes/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ func SetupAuthRoutes(router *gin.Engine, db *gorm.DB) clerk.Client {

authRoutes := router.Group("/auth")
{
// Initialize Clerk middleware
// injectActiveSession := clerk.WithSessionV2(client)
// router.Use(adaptHTTPHandler(injectActiveSession(http.HandlerFunc(returnActiveSession))))

authRoutes.POST("/register", func(c *gin.Context) {
authController.AuthenticateSession(c, client)
authController.Register(c)
})
authRoutes.POST("/authenticate", func(c *gin.Context) {
authController.AuthenticateSession(c, client)
})
authRoutes.GET("/session", func(c *gin.Context) {
authController.GetSession(c, client)
})
}

return client
Expand Down
17 changes: 15 additions & 2 deletions backend/src/routes/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ func SetupUserRoutes(router *gin.Engine, db *gorm.DB, clerkClient clerk.Client)
userRoutes := router.Group("/users")
{
/* Protected Routes */
SetupAuthMiddleware(clerkClient, router)

/*
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Clerk middleware currently doesn't work since ngrok does not allow us to
edit request headers.
We can:
- implement our own clerk middleware
- find out how to modify request headers with axios and bypass ngrok
- find out how to modify request headers with ngrok options dynamically
- add middleware to filter all requests and attach headers once they reach the backend (might conflict with clerk)
*/
// SetupAuthMiddleware(clerkClient, router)
userRoutes.PUT("/:id", userController.UpdateUserById)
userRoutes.DELETE("/:id", userController.DeleteUserById)

Expand All @@ -27,7 +40,7 @@ func SetupUserRoutes(router *gin.Engine, db *gorm.DB, clerkClient clerk.Client)
userRoutes.DELETE("/short-term-goal/:user_id/:goal_id", userController.DeleteShortTermGoalForUser)

/* Public Routes */
RemoveMiddleware(router)
// RemoveMiddleware(router)
userRoutes.POST("/", userController.CreateUser)
userRoutes.GET("/", userController.GetAllUsers)
userRoutes.GET("/:id", userController.GetUserById)
Expand Down

0 comments on commit 4d7cbe7

Please sign in to comment.