Skip to content

Commit 648dd28

Browse files
committed
fix: set user_id in context for service account auth path to prevent panic on project creation
1 parent 154befa commit 648dd28

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

internal/api/base_handler.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,22 @@ func (h *BaseHandler) respondWithJSON(c *gin.Context, code int, payload interfac
3131
// getUserID extracts the user ID from the context
3232
func (h *BaseHandler) getUserID(c *gin.Context) string {
3333
userID, _ := c.Get("user_id")
34-
return userID.(string)
34+
s, _ := userID.(string)
35+
return s
3536
}
3637

3738
// getTeamID extracts the team ID from the context
3839
func (h *BaseHandler) getTeamID(c *gin.Context) string {
3940
teamID, _ := c.Get("team_id")
40-
return teamID.(string)
41+
s, _ := teamID.(string)
42+
return s
4143
}
4244

4345
// getUserRole extracts the user role from the context
4446
func (h *BaseHandler) getUserRole(c *gin.Context) string {
4547
role, _ := c.Get("role")
46-
return role.(string)
48+
s, _ := role.(string)
49+
return s
4750
}
4851

4952
// isAdmin checks if the user has admin role
@@ -60,10 +63,11 @@ func (h *BaseHandler) isManager(c *gin.Context) bool {
6063
// getUserEmail extracts the user email from the context
6164
func (h *BaseHandler) getUserEmail(c *gin.Context) string {
6265
email, _ := c.Get("user_email")
63-
return email.(string)
66+
s, _ := email.(string)
67+
return s
6468
}
6569

6670
// ErrorResponse sends an error response with the given status code and message
6771
func (h *BaseHandler) ErrorResponse(c *gin.Context, code int, message string) {
6872
h.respondWithError(c, code, message)
69-
}
73+
}

internal/domains/auth/interfaces/middleware_adapter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func (m *AuthMiddlewareAdapter) RequireAuth() gin.HandlerFunc {
180180

181181
// Set the service account user in context
182182
c.Set("user", serviceAccountUser)
183+
c.Set("user_id", userID)
183184
c.Set("is_service_account", true)
184185
c.Next()
185186
return

0 commit comments

Comments
 (0)