Skip to content

Commit f3bce86

Browse files
committed
Move error message to route
1 parent 810e996 commit f3bce86

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

coderd/coderd.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -626,13 +626,7 @@ func New(options *Options) *API {
626626
r.Use(
627627
apiKeyMiddleware,
628628
)
629-
if allowOauthConversion {
630-
r.Post("/", api.postConvertLoginType)
631-
} else {
632-
r.Post("/", func(rw http.ResponseWriter, r *http.Request) {
633-
http.Error(rw, "Oauth conversion is not allowed, contact an administrator to turn on this feature.", http.StatusForbidden)
634-
})
635-
}
629+
r.Post("/", api.postConvertLoginType)
636630
})
637631
})
638632
r.Group(func(r chi.Router) {

coderd/userauth.go

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ const mergeStateStringPrefix = "convert-"
5050
// @Success 201 {object} codersdk.OauthConversionResponse
5151
// @Router /users/convert-login [post]
5252
func (api *API) postConvertLoginType(rw http.ResponseWriter, r *http.Request) {
53+
if !api.Options.DeploymentValues.EnableOauthAccountConversion.Value() {
54+
httpapi.Write(r.Context(), rw, http.StatusForbidden, codersdk.Response{
55+
Message: "Oauth conversion is not allowed, contact an administrator to turn on this feature.",
56+
})
57+
return
58+
}
59+
5360
var (
5461
ctx = r.Context()
5562
auditor = api.Auditor.Load()

0 commit comments

Comments
 (0)