99 "net/http"
1010 "os"
1111
12- "github.com/dxta-dev/app/internal/internal_api"
1312 "github.com/go-chi/jwtauth/v5"
1413)
1514
@@ -92,8 +91,7 @@ type contextKey struct {
9291}
9392
9493var (
95- OrganizationIdCtxKey = contextKey {"organizationId" }
96- ApiStateCtxKey = contextKey {"apiState" }
94+ AuthIdCtxKey = contextKey {"authId" }
9795)
9896
9997func Authenticator () func (http.Handler ) http.Handler {
@@ -116,36 +114,14 @@ func Authenticator() func(http.Handler) http.Handler {
116114 authId := claims ["organizationId" ].(string )
117115
118116 if authId == "" {
119- fmt .Println ("No organization id found in JWT payload" )
117+ fmt .Println ("No auth id found in JWT payload" )
120118 JSONError (w , ErrorParam {Error : "Bad request" }, http .StatusBadRequest )
121119 return
122120 }
123121
124122 ctx := r .Context ()
125123
126- tenantData , err := internal_api .GetTenantDBUrlByAuthId (ctx , authId )
127-
128- if err != nil {
129- JSONError (w , ErrorParam {Error : "Internal Server Error" }, http .StatusInternalServerError )
130- return
131- }
132-
133- apiState , err := internal_api .InternalApiState (tenantData .DBUrl , r )
134-
135- if err != nil {
136- JSONError (w , ErrorParam {Error : "Internal Server Error" }, http .StatusInternalServerError )
137- return
138- }
139-
140- organizationId , err := apiState .DB .GetOrganizationIdByAuthId (authId , ctx )
141-
142- if err != nil {
143- JSONError (w , ErrorParam {Error : "Bad request" }, http .StatusBadRequest )
144- return
145- }
146-
147- ctx = context .WithValue (ctx , OrganizationIdCtxKey , organizationId )
148- ctx = context .WithValue (ctx , ApiStateCtxKey , apiState )
124+ ctx = context .WithValue (ctx , AuthIdCtxKey , authId )
149125
150126 next .ServeHTTP (w , r .WithContext (ctx ))
151127 }
0 commit comments