diff --git a/packages/grafana-runtime/src/config.ts b/packages/grafana-runtime/src/config.ts index ec4ebf73b75..2762a6d5729 100644 --- a/packages/grafana-runtime/src/config.ts +++ b/packages/grafana-runtime/src/config.ts @@ -79,7 +79,7 @@ export class GrafanaBootConfig implements GrafanaConfig { disableUserSignUp = false; loginHint = ''; passwordHint = ''; - loginError = undefined; + loginError: string | undefined = undefined; viewersCanEdit = false; editorsCanAdmin = false; disableSanitizeHtml = false; diff --git a/public/app/core/components/Login/LoginCtrl.tsx b/public/app/core/components/Login/LoginCtrl.tsx index 370c62159c6..7adf963eed4 100644 --- a/public/app/core/components/Login/LoginCtrl.tsx +++ b/public/app/core/components/Login/LoginCtrl.tsx @@ -1,8 +1,6 @@ import React, { PureComponent } from 'react'; -import { AppEvents } from '@grafana/data'; import { FetchError, getBackendSrv, isFetchError } from '@grafana/runtime'; -import appEvents from 'app/core/app_events'; import config from 'app/core/config'; import { t } from 'app/core/internationalization'; @@ -53,11 +51,8 @@ export class LoginCtrl extends PureComponent { isLoggingIn: false, isChangingPassword: false, showDefaultPasswordWarning: false, + loginErrorMessage: config.loginError, }; - - if (config.loginError) { - appEvents.emit(AppEvents.alertWarning, ['Login Failed', config.loginError]); - } } changePassword = (password: string) => { diff --git a/public/app/core/components/Login/LoginPage.test.tsx b/public/app/core/components/Login/LoginPage.test.tsx index 319d5684229..fba3892af2b 100644 --- a/public/app/core/components/Login/LoginPage.test.tsx +++ b/public/app/core/components/Login/LoginPage.test.tsx @@ -105,6 +105,16 @@ describe('Login Page', () => { expect(screen.getByRole('link', { name: 'Sign in with Okta Test' })).toBeInTheDocument(); }); + it('shows oauth errors', async () => { + runtimeMock.config.loginError = 'Oh no there was an error :('; + + render(); + + const alert = await screen.findByRole('alert', { name: 'Login failed' }); + expect(alert).toBeInTheDocument(); + expect(alert).toHaveTextContent('Oh no there was an error :('); + }); + it('shows an error with incorrect password', async () => { postMock.mockRejectedValueOnce({ data: { @@ -122,7 +132,9 @@ describe('Login Page', () => { await userEvent.type(screen.getByLabelText('Password input field'), 'test'); await userEvent.click(screen.getByRole('button', { name: 'Login button' })); - expect(await screen.findByRole('alert', { name: 'Invalid username or password' })).toBeInTheDocument(); + const alert = await screen.findByRole('alert', { name: 'Login failed' }); + expect(alert).toBeInTheDocument(); + expect(alert).toHaveTextContent('Invalid username or password'); }); it('shows a different error with failed login attempts', async () => { @@ -142,10 +154,10 @@ describe('Login Page', () => { await userEvent.type(screen.getByLabelText('Password input field'), 'test'); await userEvent.click(screen.getByRole('button', { name: 'Login button' })); - expect( - await screen.findByRole('alert', { - name: 'You have exceeded the number of login attempts for this user. Please try again later.', - }) - ).toBeInTheDocument(); + const alert = await screen.findByRole('alert', { name: 'Login failed' }); + expect(alert).toBeInTheDocument(); + expect(alert).toHaveTextContent( + 'You have exceeded the number of login attempts for this user. Please try again later.' + ); }); }); diff --git a/public/app/core/components/Login/LoginPage.tsx b/public/app/core/components/Login/LoginPage.tsx index e19aa78cb85..e86dd4a3b28 100644 --- a/public/app/core/components/Login/LoginPage.tsx +++ b/public/app/core/components/Login/LoginPage.tsx @@ -6,6 +6,7 @@ import React from 'react'; import { Alert, HorizontalGroup, LinkButton } from '@grafana/ui'; import { Branding } from 'app/core/components/Branding/Branding'; import config from 'app/core/config'; +import { t } from 'app/core/internationalization'; import { ChangePassword } from '../ForgottenPassword/ChangePassword'; @@ -44,7 +45,11 @@ export const LoginPage = () => { {!isChangingPassword && ( - {loginErrorMessage && } + {loginErrorMessage && ( + + {loginErrorMessage} + + )} {!disableLoginForm && ( diff --git a/public/locales/de-DE/grafana.json b/public/locales/de-DE/grafana.json index 701777cf7f8..4bbc232a20e 100644 --- a/public/locales/de-DE/grafana.json +++ b/public/locales/de-DE/grafana.json @@ -254,6 +254,7 @@ "error": { "blocked": "", "invalid-user-or-password": "", + "title": "", "unknown": "" } }, diff --git a/public/locales/en-US/grafana.json b/public/locales/en-US/grafana.json index cccb1961dcd..8b58210dc91 100644 --- a/public/locales/en-US/grafana.json +++ b/public/locales/en-US/grafana.json @@ -254,6 +254,7 @@ "error": { "blocked": "You have exceeded the number of login attempts for this user. Please try again later.", "invalid-user-or-password": "Invalid username or password", + "title": "Login failed", "unknown": "Unknown error occurred" } }, diff --git a/public/locales/es-ES/grafana.json b/public/locales/es-ES/grafana.json index 19fd1905aac..78f29b1bbcd 100644 --- a/public/locales/es-ES/grafana.json +++ b/public/locales/es-ES/grafana.json @@ -259,6 +259,7 @@ "error": { "blocked": "", "invalid-user-or-password": "", + "title": "", "unknown": "" } }, diff --git a/public/locales/fr-FR/grafana.json b/public/locales/fr-FR/grafana.json index 1c7adcf59d6..bf54e45a408 100644 --- a/public/locales/fr-FR/grafana.json +++ b/public/locales/fr-FR/grafana.json @@ -259,6 +259,7 @@ "error": { "blocked": "", "invalid-user-or-password": "", + "title": "", "unknown": "" } }, diff --git a/public/locales/pseudo-LOCALE/grafana.json b/public/locales/pseudo-LOCALE/grafana.json index 85f021ff763..19db8e4f407 100644 --- a/public/locales/pseudo-LOCALE/grafana.json +++ b/public/locales/pseudo-LOCALE/grafana.json @@ -254,6 +254,7 @@ "error": { "blocked": "Ÿőū ĥävę ęχčęęđęđ ŧĥę ʼnūmþęř őƒ ľőģįʼn äŧŧęmpŧş ƒőř ŧĥįş ūşęř. Pľęäşę ŧřy äģäįʼn ľäŧęř.", "invalid-user-or-password": "Ĩʼnväľįđ ūşęřʼnämę őř päşşŵőřđ", + "title": "Ŀőģįʼn ƒäįľęđ", "unknown": "Ůʼnĸʼnőŵʼn ęřřőř őččūřřęđ" } }, diff --git a/public/locales/zh-Hans/grafana.json b/public/locales/zh-Hans/grafana.json index 24577491dab..fe69d8f1f38 100644 --- a/public/locales/zh-Hans/grafana.json +++ b/public/locales/zh-Hans/grafana.json @@ -249,6 +249,7 @@ "error": { "blocked": "", "invalid-user-or-password": "", + "title": "", "unknown": "" } },