Skip to content

Commit d2bc5b8

Browse files
committed
feat: UI Shows suspended error logging into suspended account
1 parent 047c234 commit d2bc5b8

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

coderd/users.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -632,15 +632,16 @@ func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) {
632632
// This message is the same as above to remove ease in detecting whether
633633
// users are registered or not. Attackers still could with a timing attack.
634634
httpapi.Write(rw, http.StatusUnauthorized, httpapi.Response{
635-
Message: "invalid email or password",
635+
Message: "Incorrect email or password",
636636
})
637637
return
638638
}
639639

640640
// If the user logged into a suspended account, reject the login request.
641641
if user.Status != database.UserStatusActive {
642+
642643
httpapi.Write(rw, http.StatusUnauthorized, httpapi.Response{
643-
Message: fmt.Sprintf("user is not active (status = %q), contact an admin to reactivate your account", user.Status),
644+
Message: "You are suspended, contact an admin to reactivate your account",
644645
})
645646
return
646647
}

site/src/components/SignInForm/SignInForm.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export const SignInForm: React.FC<SignInFormProps> = ({
110110
type="password"
111111
variant="outlined"
112112
/>
113-
{authErrorMessage && <FormHelperText error>{Language.authErrorMessage}</FormHelperText>}
113+
{authErrorMessage && <FormHelperText error>{authErrorMessage}</FormHelperText>}
114114
{methodsErrorMessage && <FormHelperText error>{Language.methodsErrorMessage}</FormHelperText>}
115115
<div className={styles.submitBtn}>
116116
<LoadingButton loading={isLoading} fullWidth type="submit" variant="contained">

site/src/pages/LoginPage/LoginPage.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { Footer } from "../../components/Footer/Footer"
66
import { SignInForm } from "../../components/SignInForm/SignInForm"
77
import { retrieveRedirect } from "../../util/redirect"
88
import { XServiceContext } from "../../xServices/StateContext"
9+
import { AxiosError } from "axios"
10+
import {isApiError} from "../../api/errors";
911

1012
export const useStyles = makeStyles((theme) => ({
1113
root: {
@@ -33,7 +35,11 @@ export const LoginPage: React.FC = () => {
3335
const [authState, authSend] = useActor(xServices.authXService)
3436
const isLoading = authState.hasTag("loading")
3537
const redirectTo = retrieveRedirect(location.search)
36-
const authErrorMessage = authState.context.authError ? (authState.context.authError as Error).message : undefined
38+
//{
39+
// "message": "user is not active (status = \"suspended\"), contact an admin to reactivate your account"
40+
// }
41+
42+
const authErrorMessage = isApiError(authState.context.authError) ? authState.context.authError.response.data.message : undefined
3743
const getMethodsError = authState.context.getMethodsError
3844
? (authState.context.getMethodsError as Error).message
3945
: undefined

site/src/xServices/auth/authXService.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { assign, createMachine } from "xstate"
22
import * as API from "../../api/api"
33
import * as TypesGen from "../../api/typesGenerated"
44
import { displayError, displaySuccess } from "../../components/GlobalSnackbar/utils"
5+
import { AxiosError } from "axios"
56

67
export const Language = {
78
successProfileUpdate: "Updated settings.",
@@ -48,7 +49,7 @@ type Permissions = Record<keyof typeof permissionsToCheck, boolean>
4849
export interface AuthContext {
4950
getUserError?: Error | unknown
5051
getMethodsError?: Error | unknown
51-
authError?: Error | unknown
52+
authError?: Error | AxiosError | unknown
5253
updateProfileError?: Error | unknown
5354
me?: TypesGen.User
5455
methods?: TypesGen.AuthMethods

0 commit comments

Comments
 (0)