Skip to content
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

SignUp/SignIn State PR (to main) #229

Merged
merged 29 commits into from
Dec 10, 2024
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
877ddeb
Add routes and initial page for sign up flow
codytodonnell Jun 11, 2024
fef70b2
Add account and policies steps to sign up flow
codytodonnell Jun 14, 2024
71a5a83
Add colors used in sign up to mui theme
codytodonnell Jun 14, 2024
b34e3c7
Fix layout in sign up alert box
codytodonnell Jun 14, 2024
7b17975
Fix container padding and nav border
codytodonnell Jul 9, 2024
231a961
Merge branch 'main' into feature/sign-up-layout
codytodonnell Jul 9, 2024
7f5b3ae
Add Login and LoginContinue support (nextrequest, choice/create still…
dauglyon Jul 18, 2024
e9967cd
fix login provider values
dauglyon Jul 18, 2024
eabe56d
support new login paths
dauglyon Jul 18, 2024
82de2b3
Add nextRequest support
dauglyon Jul 31, 2024
c7a8039
Add login tests
dauglyon Jul 31, 2024
81b6d26
Add loggout page, implement legacy login/out redirect
dauglyon Aug 1, 2024
ab62bb0
clear narrative_session on logout
dauglyon Aug 1, 2024
5c2e7db
Add LoginContinue tests
dauglyon Aug 6, 2024
d1d8ba4
Merge remote-tracking branch 'origin/login-partial-1' into sign-up-state
dauglyon Aug 16, 2024
e1dd331
Merge remote-tracking branch 'origin/feature/sign-up-layout' into sig…
dauglyon Aug 16, 2024
bd16347
steps 1-2 (squashed), initial T&C commits
dauglyon Dec 3, 2024
284fd3c
policy enforcment and signup API commits (squashed)
dauglyon Dec 4, 2024
16b2caa
fix filename casing issue
dauglyon Dec 4, 2024
0a69092
fix existing tests
dauglyon Dec 4, 2024
c003bf0
add policy renewal message, fix bugs
dauglyon Dec 4, 2024
4ef44b3
updated T&C, better login buttons
dauglyon Dec 5, 2024
19d433c
update T&C
dauglyon Dec 5, 2024
23858e8
bugfix for signup policy dispatch/query race condition
dauglyon Dec 5, 2024
fbb48e8
bugfix for signup policy dispatch/query race condition
dauglyon Dec 5, 2024
93f53e8
Merge branch 'sign-up-state' of github.com:kbase/ui into sign-up-state
dauglyon Dec 6, 2024
6a2bcfe
code cleanup before merging tests
dauglyon Dec 6, 2024
0668a0e
add back in refactored tests
dauglyon Dec 6, 2024
904306d
fix loader error
dauglyon Dec 7, 2024
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
492 changes: 472 additions & 20 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -33,7 +33,10 @@
"d3-zoom": "^3.0.0",
"dompurify": "^3.0.1",
"downsample-lttb-ts": "^0.0.6",
"front-matter": "^4.0.2",
"jest-fetch-mock": "^3.0.3",
"js-md5": "^0.8.3",
"kbase-policies": "github:kbase/policies",
"leaflet": "^1.9.4",
"marked": "^4.2.12",
"node-sass": "^9.0.0",
3 changes: 3 additions & 0 deletions src/app/App.module.scss
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@

.left_navbar {
background-color: use-color("white");
border-right: 1px solid use-color("silver");
flex-grow: 0;
flex-shrink: 0;
max-height: 100%;
@@ -53,6 +54,8 @@
flex-shrink: 1;
max-height: 100%;
overflow-y: auto;
padding-bottom: 1rem;
padding-top: 1rem;
position: relative;
}
}
4 changes: 2 additions & 2 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
@@ -60,15 +60,15 @@ const App: FC = () => {
<div className={classes.left_navbar}>
<LeftNavBar />
</div>
<div className={classes.page_content}>
<main className={classes.page_content}>
<ErrorBoundary FallbackComponent={ErrorPage}>
<Loader loading={isLoading}>
<Routes />
</Loader>
<Toaster />
<ModalDialog />
</ErrorBoundary>
</div>
</main>
</div>
</div>
);
25 changes: 21 additions & 4 deletions src/app/Routes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FC, ReactElement } from 'react';
import {
createSearchParams,
Navigate,
Route,
Routes as RRRoutes,
@@ -27,17 +28,23 @@ import {
} from '../common/hooks';
import ORCIDLinkFeature from '../features/orcidlink';
import { LogIn } from '../features/login/LogIn';
import { LogInContinue } from '../features/login/LogInContinue';
import { LoggedOut } from '../features/login/LoggedOut';
import { SignUp } from '../features/signup/SignUp';
import ORCIDLinkCreateLink from '../features/orcidlink/CreateLink';

export const LOGIN_ROUTE = '/legacy/login';
export const LOGIN_ROUTE = '/login';
export const SIGNUP_ROUTE = '/signup';
export const ROOT_REDIRECT_ROUTE = '/narratives';

const Routes: FC = () => {
useFilteredParams();
usePageTracking();
return (
<RRRoutes>
{/* Legacy */}
<Route path={`${LEGACY_BASE_ROUTE}/*`} element={<Legacy />} />

<Route path="/status" element={<Status />} />
<Route
path="/profile/:usernameRequested/narratives"
@@ -54,6 +61,11 @@ const Routes: FC = () => {

{/* Log In */}
<Route path="/login" element={<LogIn />} />
<Route path="/login/continue" element={<LogInContinue />} />
<Route path="/loggedout" element={<LoggedOut />} />

{/* Sign Up */}
<Route path={`${SIGNUP_ROUTE}/:step?`} element={<SignUp />} />

{/* Navigator */}
<Route
@@ -119,14 +131,19 @@ const Routes: FC = () => {
export const Authed: FC<{ element: ReactElement }> = ({ element }) => {
const token = useAppSelector((state) => state.auth.token);
const location = useLocation();
if (!token)
if (!token) {
return (
<Navigate
to={LOGIN_ROUTE}
to={{
pathname: LOGIN_ROUTE,
search: createSearchParams({
nextRequest: JSON.stringify(location),
}).toString(),
}}
replace
state={{ preLoginPath: location.pathname }}
/>
);
}

return <>{element}</>;
};
2 changes: 2 additions & 0 deletions src/app/store.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import navigator from '../features/navigator/navigatorSlice';
import orcidlink from '../features/orcidlink/orcidlinkSlice';
import params from '../features/params/paramsSlice';
import profile from '../features/profile/profileSlice';
import signup from '../features/signup/SignupSlice';

const everyReducer = combineReducers({
auth,
@@ -18,6 +19,7 @@ const everyReducer = combineReducers({
params,
profile,
orcidlink,
signup,
[baseApi.reducerPath]: baseApi.reducer,
});

129 changes: 127 additions & 2 deletions src/common/api/authService.ts
Original file line number Diff line number Diff line change
@@ -30,12 +30,73 @@ interface AuthParams {
search: string;
token: string;
};
getLoginChoice: void;
postLoginPick: { id: string; policyids: string[] };
loginUsernameSuggest: string;
loginCreate: {
id: string;
user: string;
display: string;
email: string;
linkall: false;
policyids: string[];
};
}

interface AuthResults {
getMe: Me;
getUsers: Record<string, string>;
searchUsers: Record<string, string>;
getLoginChoice: {
// cancelurl: string;
create: {
availablename: string;
id: string;
provemail: string;
provfullname: string;
provusername: string;
}[];
// createurl: string;
creationallowed: true;
expires: number;
login: {
adminonly: boolean;
disabled: boolean;
id: string;
loginallowed: true;
policyids: {
agreedon: number;
id: string;
}[];
provusernames: string[];
user: string;
}[];
// pickurl: string;
provider: string;
// redirecturl: string | null;
// suggestnameurl: string;
};
postLoginPick: {
redirecturl: null | string;
token: {
agent: string;
agentver: string;
created: number;
custom: unknown;
device: unknown;
expires: number;
id: string;
ip: string;
name: unknown;
os: unknown;
osver: unknown;
token: string;
type: string;
user: string;
};
};
loginUsernameSuggest: { availablename: string };
loginCreate: AuthResults['postLoginPick'];
}

// Auth does not use JSONRpc, so we use queryFn to make custom queries
@@ -102,8 +163,72 @@ export const authApi = baseApi.injectEndpoints({
method: 'DELETE',
}),
}),
getLoginChoice: builder.query<
AuthResults['getLoginChoice'],
AuthParams['getLoginChoice']
>({
query: () =>
// MUST have an in-process-login-token cookie
authService({
headers: {
accept: 'application/json',
},
method: 'GET',
url: '/login/choice',
}),
}),
postLoginPick: builder.mutation<
AuthResults['postLoginPick'],
AuthParams['postLoginPick']
>({
query: (pickedChoice) =>
authService({
url: encode`/login/pick`,
body: pickedChoice,
method: 'POST',
}),
}),
loginUsernameSuggest: builder.query<
AuthResults['loginUsernameSuggest'],
AuthParams['loginUsernameSuggest']
>({
query: (username) =>
// MUST have an in-process-login-token cookie
authService({
headers: {
accept: 'application/json',
},
method: 'GET',
url: `/login/suggestname/${encodeURIComponent(username)}`,
}),
}),
loginCreate: builder.mutation<
AuthResults['loginCreate'],
AuthParams['loginCreate']
>({
query: (params) =>
// MUST have an in-process-login-token cookie
authService({
headers: {
accept: 'application/json',
},
method: 'POST',
body: params,
url: `/login/create/`,
}),
}),
}),
});

export const { authFromToken, getMe, getUsers, searchUsers, revokeToken } =
authApi.endpoints;
export const {
authFromToken,
getMe,
getUsers,
searchUsers,
revokeToken,
getLoginChoice,
postLoginPick,
loginUsernameSuggest,
loginCreate,
} = authApi.endpoints;
export type GetLoginChoiceResult = AuthResults['getLoginChoice'];
22 changes: 14 additions & 8 deletions src/common/api/userProfileApi.ts
Original file line number Diff line number Diff line change
@@ -8,12 +8,15 @@ const userProfile = jsonRpcService({
interface UserProfileParams {
status: void;
get_user_profile: { usernames: string[] };
set_user_profile: {
set_user_profile: [
profile: {
user: { username: string; realname: string };
profile: unknown;
};
};
profile: {
user: { username: string; realname: string };
profile: unknown;
};
},
optionalToken: string | undefined
];
}

interface UserProfileResults {
@@ -64,13 +67,16 @@ export const userProfileApi = baseApi
UserProfileResults['set_user_profile'],
UserProfileParams['set_user_profile']
>({
query: ({ profile }) =>
query: ([profile, optionalToken]) =>
userProfile({
fetchArgs: optionalToken
? { headers: { Authorization: optionalToken } }
: {},
method: 'UserProfile.set_user_profile',
params: [{ profile }],
params: [profile],
}),
// Invalidates the cache for any queries with a matching tag
invalidatesTags: (result, error, { profile }) => [
invalidatesTags: (result, error, [{ profile }]) => [
{ type: 'Profile', id: profile.user.username },
],
}),
2 changes: 1 addition & 1 deletion src/common/api/utils/kbaseBaseQuery.ts
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ export interface JsonRpcQueryArgs {
service: StaticService | DynamicService;
method: string;
params?: unknown;
fetchArgs?: FetchArgs;
fetchArgs?: Partial<FetchArgs>;
}

export interface JSONRPC11Body {
2 changes: 1 addition & 1 deletion src/common/types/auth.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ export interface Me {
idents: Record<string, string>[];
lastlogin: number;
local: boolean;
policyids: Record<string, string | number>[];
policyids: { id: string; agreedon: number }[];
roles: Record<string, string>[];
user: string;
}
4 changes: 1 addition & 3 deletions src/features/collections/Collections.module.scss
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@
$border: 1px solid use-color("base-lighter");

.collections-main {
background-color: use-color("base-lightest");
border-left: 1px solid use-color("silver");
min-height: 100%;
}

@@ -22,7 +20,7 @@ $border: 1px solid use-color("base-lighter");
font-size: 1.25rem;
font-weight: 500;
margin: 0;
padding: 2rem 1rem 1rem;
padding: 1rem;
}

.collection-card {
Loading
Loading