Skip to content
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
Next Next commit
Allow providing login form details via GET params
  • Loading branch information
beastafk committed Nov 13, 2024
commit 7c69d0675c6c62812a7d01d943fbfa3fd21b74f7
7 changes: 6 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { AppContext } from "./AppContext";
import storage from "./storage";

// load config.json
let props: Config = {};
let props: Config = {
restrictBaseUrl: [],
asManagedUsers: [],
supportURL: "",
menu: [],
};
try {
const resp = await fetch("config.json");
const configJSON = await resp.json();
Expand Down
23 changes: 19 additions & 4 deletions src/pages/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ const LoginPage = () => {

const handleSubmit = auth => {
setLoading(true);
const cleanUrl = window.location.href.replace(window.location.search, "");
window.history.replaceState({}, "", cleanUrl);

login(auth).catch(error => {
setLoading(false);
notify(
Expand Down Expand Up @@ -166,6 +169,18 @@ const LoginPage = () => {
.catch(() => setSSOBaseUrl(""));
}, [formData.base_url, form]);

useEffect(() => {
const params = new URLSearchParams(window.location.search);
const username = params.get("username");
const serverURL = params.get("server");
if (username) {
form.setValue("username", username);
}
if (serverURL) {
form.setValue("base_url", serverURL);
}
}, [window.location.search]);

return (
<>
<Tabs
Expand All @@ -186,10 +201,10 @@ const LoginPage = () => {
source="username"
label="ra.auth.username"
autoComplete="username"
disabled={loading || !supportPassAuth}
onBlur={handleUsernameChange}
resettable
validate={required()}
{...(loading || !supportPassAuth ? { disabled: true } : {})}
/>
</Box>
<Box>
Expand All @@ -198,7 +213,7 @@ const LoginPage = () => {
label="ra.auth.password"
type="password"
autoComplete="current-password"
disabled={loading || !supportPassAuth}
{...(loading || !supportPassAuth ? { disabled: true } : {})}
resettable
validate={required()}
/>
Expand All @@ -209,7 +224,7 @@ const LoginPage = () => {
<TextInput
source="accessToken"
label="synapseadmin.auth.access_token"
disabled={loading}
{...(loading ? { disabled: true } : {})}
resettable
validate={required()}
/>
Expand All @@ -221,7 +236,7 @@ const LoginPage = () => {
label="synapseadmin.auth.base_url"
select={allowMultipleBaseUrls}
autoComplete="url"
disabled={loading}
{...(loading ? { disabled: true } : {})}
readOnly={allowSingleBaseUrl}
resettable={allowAnyBaseUrl}
validate={[required(), validateBaseUrl]}
Expand Down