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)
| 140 | // @Success 200 {object} codersdk.Response |
| 141 | // @Router /api/v2/users/first [get] |
| 142 | func (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 | // |
nothing calls this directly
no test coverage detected