Skip to content

Commit f2bf653

Browse files
authored
Redesign login page + hide login form when SSO is enabled (#4610)
* Display only SSO buttons if SSO is enabled * renamed sign in to login/log in
1 parent b61b3ba commit f2bf653

File tree

20 files changed

+180
-137
lines changed

20 files changed

+180
-137
lines changed

frontend/app/cypress/support/e2e.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ Cypress.Commands.add("login", (username: string, password: string) => {
2525
cy.session(
2626
[username, password],
2727
() => {
28-
cy.visit("/signin");
29-
cy.contains("Sign in to your account").should("be.visible");
28+
cy.visit("/login");
29+
cy.contains("Log in to your account").should("be.visible");
3030

3131
cy.get(":nth-child(1) > .relative > .block").type(username);
3232

frontend/app/package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"sha1": "^1.1.1",
8888
"subscriptions-transport-ws": "^0.11.0",
8989
"tailwind-merge": "^2.2.2",
90+
"tailwindcss-animate": "^1.0.7",
9091
"unidiff": "^1.0.4",
9192
"use-query-params": "^2.2.1",
9293
"vite": "^5.2.8",

frontend/app/src/components/account-menu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const UnauthenticatedAccountMenu = () => {
7878
<DropdownMenu>
7979
<Link
8080
className="flex items-center h-14 rounded-lg p-2 gap-2 hover:bg-indigo-50"
81-
to="/signin"
81+
to="/login"
8282
state={{ from: location }}
8383
>
8484
<div className="bg-indigo-50 rounded-full h-10 w-10 flex items-center justify-center overflow-hidden border border-white">
@@ -111,7 +111,7 @@ const UnauthenticatedAccountMenu = () => {
111111
<CommonMenuItems />
112112
<DropdownMenuDivider />
113113
<DropdownMenuItem asChild>
114-
<Link to="/signin" state={{ from: location }}>
114+
<Link to="/login" state={{ from: location }}>
115115
<Icon icon="mdi:login" className="text-base" />
116116
Log in
117117
</Link>

frontend/app/src/components/conversations/add-comment.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ export const AddComment = forwardRef<FormRef, tAddComment>(({ onSubmit, onCancel
6060
<LinkButton
6161
size="sm"
6262
variant="primary"
63-
to={constructPath("/signin")}
63+
to={constructPath("/login")}
6464
state={{ from: location }}
6565
>
66-
Sign in
66+
Login
6767
</LinkButton>{" "}
6868
to be able to add a comment.
6969
</div>

frontend/app/src/config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const CONFIG = {
3131
SEARCH_URL: (query: string, limit: number = 3) =>
3232
`${INFRAHUB_API_SERVER_URL}/api/search/docs?query=${query}&limit=${limit}`,
3333
INFO_URL: `${INFRAHUB_API_SERVER_URL}/api/info`,
34-
AUTH_SIGN_IN_URL: `${INFRAHUB_API_SERVER_URL}/api/auth/login`,
34+
AUTH_LOGIN_URL: `${INFRAHUB_API_SERVER_URL}/api/auth/login`,
3535
SCHEMA_SUMMARY_URL: (branch?: string | null) =>
3636
branch
3737
? `${INFRAHUB_API_SERVER_URL}/api/schema/summary?branch=${branch}`

frontend/app/src/hooks/useAuth.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export type AuthContextType = {
3030
isAuthenticated: boolean;
3131
isLoading: boolean;
3232
permissions?: PermissionsType;
33-
signIn: (data: { username: string; password: string }, callback?: () => void) => Promise<void>;
33+
login: (data: { username: string; password: string }, callback?: () => void) => Promise<void>;
3434
signOut: (callback?: () => void) => void;
3535
setToken: (token: UserToken) => void;
3636
user: User | null;
@@ -90,7 +90,7 @@ export const AuthContext = createContext<AuthContextType>({
9090
isAdmin: false,
9191
write: false,
9292
},
93-
signIn: async () => {},
93+
login: async () => {},
9494
signOut: () => {},
9595
setToken: () => {},
9696
user: null,
@@ -113,7 +113,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
113113
};
114114

115115
const result: components["schemas"]["UserToken"] = await fetchUrl(
116-
CONFIG.AUTH_SIGN_IN_URL,
116+
CONFIG.AUTH_LOGIN_URL,
117117
payload
118118
);
119119

@@ -147,7 +147,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
147147
write: WRITE_ROLES.includes(data?.user_claims?.role),
148148
isAdmin: ADMIN_ROLES.includes(data?.user_claims?.role),
149149
},
150-
signIn,
150+
login: signIn,
151151
signOut,
152152
setToken,
153153
user: data?.sub ? { id: data?.sub } : null,
@@ -167,9 +167,9 @@ export function RequireAuth({ children }: { children: ReactElement }) {
167167

168168
if (isAuthenticated || config?.main?.allow_anonymous_access) return children;
169169

170-
// Redirect them to the /signin page, but save the current location they were
170+
// Redirect them to the /login page, but save the current location they were
171171
// trying to go to when they were redirected. This allows us to send them
172172
// along to that page after they log in, which is a nicer user experience
173173
// than dropping them off on the home page.
174-
return <Navigate to="/signin" state={{ from: location }} replace />;
174+
return <Navigate to="/login" state={{ from: location }} replace />;
175175
}

frontend/app/src/pages/auth-callback.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ function AuthCallback() {
4242
}, [config, protocol, provider]);
4343

4444
if (!config || !config.sso.enabled) {
45-
return <Navigate to="/signin" replace />;
45+
return <Navigate to="/login" replace />;
4646
}
4747

4848
if (errors) {
49-
return <Navigate to="/signin" state={{ errors }} replace />;
49+
return <Navigate to="/login" state={{ errors }} replace />;
5050
}
5151

5252
if (isAuthenticated) {

frontend/app/src/pages/login.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { useAuth } from "@/hooks/useAuth";
2+
import { ReactComponent as InfrahubLogo } from "@/images/Infrahub-SVG-hori.svg";
3+
import { Login } from "@/screens/authentification/login";
4+
import Content from "@/screens/layout/content";
5+
import { Navigate, useLocation } from "react-router-dom";
6+
7+
function LoginPage() {
8+
const location = useLocation();
9+
const { isAuthenticated } = useAuth();
10+
11+
if (isAuthenticated) {
12+
const from = (location.state?.from?.pathname || "/") + (location.state?.from?.search ?? "");
13+
return <Navigate to={from} replace />;
14+
}
15+
16+
return (
17+
<Content className="bg-stone-100 h-screen w-screen pt-[25vh]">
18+
<div className="flex flex-col items-center gap-6 w-full max-w-sm m-auto">
19+
<InfrahubLogo className="h-12" alt="Intrahub logo" />
20+
21+
<h1 className="text-xl font-semibold text-neutral-900">Log in to your account</h1>
22+
23+
<Login />
24+
25+
{location?.state?.errors?.map(
26+
(error: { extensions: { code: number }; message: string }, index: number) => (
27+
<p key={index} className="text-red-500 text-sm mt-2">
28+
({error.extensions.code}) {error.message}
29+
</p>
30+
)
31+
)}
32+
</div>
33+
</Content>
34+
);
35+
}
36+
37+
export const Component = LoginPage;

frontend/app/src/pages/sign-in.tsx

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)