diff --git a/web/packages/teleport/src/Login/Login.test.tsx b/web/packages/teleport/src/Login/Login.test.tsx
index 8102775cb9653..61ee3d1d1d1d2 100644
--- a/web/packages/teleport/src/Login/Login.test.tsx
+++ b/web/packages/teleport/src/Login/Login.test.tsx
@@ -114,41 +114,62 @@ test('login with private key policy enabled through role setting', async () => {
expect(screen.getByText(/login disabled/i)).toBeInTheDocument();
});
-test('show motd only if motd is set', async () => {
- // default login form
- const { unmount } = render();
- expect(screen.getByPlaceholderText(/username/i)).toBeInTheDocument();
- expect(
- screen.queryByText('Welcome to cluster, your activity will be recorded.')
- ).not.toBeInTheDocument();
- unmount();
-
- // now set motd
- jest
- .spyOn(cfg, 'getMotd')
- .mockImplementation(
- () => 'Welcome to cluster, your activity will be recorded.'
- );
-
- render();
-
- expect(
- screen.getByText('Welcome to cluster, your activity will be recorded.')
- ).toBeInTheDocument();
- expect(screen.queryByPlaceholderText(/username/i)).not.toBeInTheDocument();
-});
+describe('test MOTD', () => {
+ test('show motd only if motd is set', async () => {
+ // default login form
+ const { unmount } = render();
+ expect(screen.getByPlaceholderText(/username/i)).toBeInTheDocument();
+ expect(
+ screen.queryByText('Welcome to cluster, your activity will be recorded.')
+ ).not.toBeInTheDocument();
+ unmount();
+
+ // now set motd
+ jest
+ .spyOn(cfg, 'getMotd')
+ .mockImplementation(
+ () => 'Welcome to cluster, your activity will be recorded.'
+ );
+
+ render();
+
+ expect(
+ screen.getByText('Welcome to cluster, your activity will be recorded.')
+ ).toBeInTheDocument();
+ expect(screen.queryByPlaceholderText(/username/i)).not.toBeInTheDocument();
+ });
-test('show login form after modt acknowledge', async () => {
- jest
- .spyOn(cfg, 'getMotd')
- .mockImplementation(
- () => 'Welcome to cluster, your activity will be recorded.'
- );
- render();
- expect(
- screen.getByText('Welcome to cluster, your activity will be recorded.')
- ).toBeInTheDocument();
+ test('show login form after modt acknowledge', async () => {
+ jest
+ .spyOn(cfg, 'getMotd')
+ .mockImplementation(
+ () => 'Welcome to cluster, your activity will be recorded.'
+ );
+ render();
+ expect(
+ screen.getByText('Welcome to cluster, your activity will be recorded.')
+ ).toBeInTheDocument();
+
+ fireEvent.click(screen.getByText('Acknowledge'));
+ expect(screen.getByPlaceholderText(/username/i)).toBeInTheDocument();
+ });
- fireEvent.click(screen.getByText('Acknowledge'));
- expect(screen.getByPlaceholderText(/username/i)).toBeInTheDocument();
+ test('skip motd if login initiated from headless auth', async () => {
+ jest
+ .spyOn(cfg, 'getMotd')
+ .mockImplementation(
+ () => 'Welcome to cluster, your activity will be recorded.'
+ );
+ jest
+ .spyOn(history, 'getRedirectParam')
+ .mockReturnValue(
+ 'https://teleport.example.com/web/headless/5c5c1f73-ac5c-52ee-bc9e-0353094dcb4a'
+ );
+
+ render();
+
+ expect(
+ screen.queryByText('Welcome to cluster, your activity will be recorded.')
+ ).not.toBeInTheDocument();
+ });
});
diff --git a/web/packages/teleport/src/Login/useLogin.ts b/web/packages/teleport/src/Login/useLogin.ts
index 5ce89419d3be4..8cc60b3a751bd 100644
--- a/web/packages/teleport/src/Login/useLogin.ts
+++ b/web/packages/teleport/src/Login/useLogin.ts
@@ -39,7 +39,14 @@ export default function useLogin() {
const auth2faType = cfg.getAuth2faType();
const isLocalAuthEnabled = cfg.getLocalAuthFlag();
const motd = cfg.getMotd();
- const [showMotd, setShowMotd] = useState(!!motd);
+ const [showMotd, setShowMotd] = useState(() => {
+ const redirectUri = history.getRedirectParam();
+
+ if (redirectUri?.includes('headless')) {
+ return false;
+ }
+ return !!cfg.getMotd();
+ });
function acknowledgeMotd() {
setShowMotd(false);