Skip to content

fix: Suspended users cannot authenticate #1849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: UI Shows suspended error logging into suspended account
  • Loading branch information
Emyrk committed May 27, 2022
commit d2bc5b82ea79baa0967c3c55c9e3b367c4019e62
5 changes: 3 additions & 2 deletions coderd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,15 +632,16 @@ func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) {
// This message is the same as above to remove ease in detecting whether
// users are registered or not. Attackers still could with a timing attack.
httpapi.Write(rw, http.StatusUnauthorized, httpapi.Response{
Message: "invalid email or password",
Message: "Incorrect email or password",
})
return
}

// If the user logged into a suspended account, reject the login request.
if user.Status != database.UserStatusActive {

httpapi.Write(rw, http.StatusUnauthorized, httpapi.Response{
Message: fmt.Sprintf("user is not active (status = %q), contact an admin to reactivate your account", user.Status),
Message: "You are suspended, contact an admin to reactivate your account",
})
return
}
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/SignInForm/SignInForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const SignInForm: React.FC<SignInFormProps> = ({
type="password"
variant="outlined"
/>
{authErrorMessage && <FormHelperText error>{Language.authErrorMessage}</FormHelperText>}
{authErrorMessage && <FormHelperText error>{authErrorMessage}</FormHelperText>}
{methodsErrorMessage && <FormHelperText error>{Language.methodsErrorMessage}</FormHelperText>}
<div className={styles.submitBtn}>
<LoadingButton loading={isLoading} fullWidth type="submit" variant="contained">
Expand Down
8 changes: 7 additions & 1 deletion site/src/pages/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Footer } from "../../components/Footer/Footer"
import { SignInForm } from "../../components/SignInForm/SignInForm"
import { retrieveRedirect } from "../../util/redirect"
import { XServiceContext } from "../../xServices/StateContext"
import { AxiosError } from "axios"
import {isApiError} from "../../api/errors";

export const useStyles = makeStyles((theme) => ({
root: {
Expand Down Expand Up @@ -33,7 +35,11 @@ export const LoginPage: React.FC = () => {
const [authState, authSend] = useActor(xServices.authXService)
const isLoading = authState.hasTag("loading")
const redirectTo = retrieveRedirect(location.search)
const authErrorMessage = authState.context.authError ? (authState.context.authError as Error).message : undefined
//{
// "message": "user is not active (status = \"suspended\"), contact an admin to reactivate your account"
// }

const authErrorMessage = isApiError(authState.context.authError) ? authState.context.authError.response.data.message : undefined
const getMethodsError = authState.context.getMethodsError
? (authState.context.getMethodsError as Error).message
: undefined
Expand Down
3 changes: 2 additions & 1 deletion site/src/xServices/auth/authXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { assign, createMachine } from "xstate"
import * as API from "../../api/api"
import * as TypesGen from "../../api/typesGenerated"
import { displayError, displaySuccess } from "../../components/GlobalSnackbar/utils"
import { AxiosError } from "axios"

export const Language = {
successProfileUpdate: "Updated settings.",
Expand Down Expand Up @@ -48,7 +49,7 @@ type Permissions = Record<keyof typeof permissionsToCheck, boolean>
export interface AuthContext {
getUserError?: Error | unknown
getMethodsError?: Error | unknown
authError?: Error | unknown
authError?: Error | AxiosError | unknown
updateProfileError?: Error | unknown
me?: TypesGen.User
methods?: TypesGen.AuthMethods
Expand Down