MCPcopy Index your code
hub / github.com/coder/coder / firstUser

Method firstUser

coderd/users.go:142–164  ·  view source on GitHub ↗

Returns whether the initial user has been created or not. @Summary Check initial user created @ID check-initial-user-created @Security CoderSessionToken @Produce json @Tags Users @Success 200 {object} codersdk.Response @Router /api/v2/users/first [get]

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

140// @Success 200 {object} codersdk.Response
141// @Router /api/v2/users/first [get]
142func (api *API) firstUser(rw http.ResponseWriter, r *http.Request) {
143 ctx := r.Context()
144 // nolint:gocritic // Getting user count is a system function.
145 userCount, err := api.Database.GetUserCount(dbauthz.AsSystemRestricted(ctx), false)
146 if err != nil {
147 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
148 Message: "Internal error fetching user count.",
149 Detail: err.Error(),
150 })
151 return
152 }
153
154 if userCount == 0 {
155 httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
156 Message: "The initial user has not been created!",
157 })
158 return
159 }
160
161 httpapi.Write(ctx, rw, http.StatusOK, codersdk.Response{
162 Message: "The initial user has already been created!",
163 })
164}
165
166// Creates the initial user for a Coder deployment.
167//

Callers

nothing calls this directly

Calls 5

AsSystemRestrictedFunction · 0.92
WriteFunction · 0.92
ContextMethod · 0.65
GetUserCountMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected