added full keycloak support. Partial Quantum backend support, Moved to

.env for config

- removed the globalVars variable for a lack of need
- changed the documentation page for test of multilevel navigation
- added machines page to route
- cleaned up dependencies for build
- changed config to split imports
This commit is contained in:
2026-04-26 16:25:02 +03:00
parent 8e78b8cb47
commit 8449da8373
33 changed files with 863 additions and 417 deletions

View File

@@ -1,28 +1,97 @@
import axios from "axios";
import { keycloakURI } from "GlobalVars";
import Keycloak from "keycloak-js";
import Keycloak, { type KeycloakProfile } from "keycloak-js";
import { routes } from "Routes/Routes";
const keycloak = new Keycloak({
url: keycloakURI,
realm: "dev-realm",
url: import.meta.env.VITE_KEYCLOAK_URL
? import.meta.env.VITE_KEYCLOAK_URL
: "",
realm: "quant_sim-realm",
clientId: "react-frontend",
});
const api = axios.create({
baseURL: `${keycloak.authServerUrl}/realms/${keycloak.realm}`,
});
export default keycloak;
export async function getProfile(keycloak: Keycloak) {
return keycloak.loadUserProfile();
}
export const handleSubmit = async (profile) => {
export const updateUserData = async (
profile: KeycloakProfile,
): Promise<KeycloakProfile | undefined> => {
try {
await api.put("/account", profile);
alert("Profile updated!");
await keycloak.updateToken(30);
const response = await axios.post(
`${keycloak.authServerUrl}/realms/${keycloak.realm}/account/`,
{
firstName: profile.firstName,
lastName: profile.lastName,
email: profile.email,
username: profile.username,
attributes: profile.attributes || {},
},
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${keycloak.token}`,
},
withCredentials: true, // Important: allows credentials in CORS
},
);
if (response.status === 204) {
// Refresh the local profile after successful update
const updatedProfile = await keycloak.loadUserProfile();
return updatedProfile;
}
} catch (err) {
console.error(err);
}
};
export const updatePasswordWithRedirect = async (
successRedirectUrl?: string,
) => {
try {
await keycloak.updateToken(30);
// Trigger the UPDATE_PASSWORD required action
// This will redirect the user to Keycloak's password change page
return keycloak.login({
action: "UPDATE_PASSWORD",
redirectUri:
successRedirectUrl ||
window.location.origin +
"/" +
import.meta.env.VITE_BASE_PATH +
"/" +
routes.SettingsPage.path +
"?password_updated=true",
// Optional: Force re-authentication
prompt: "login",
});
} catch (error) {
console.error("Failed to initiate password update:", error);
throw error;
}
};
export const SendEmailVerification = async () => {
try {
await keycloak.updateToken(30);
// Trigger the UPDATE_PASSWORD required action
// This will redirect the user to Keycloak's password change page
return keycloak.login({
action: "VERIFY_EMAIL",
redirectUri:
window.location.origin +
import.meta.env.VITE_BASE_PATH +
"/" +
routes.SettingsPage.path +
"?email_sent=true",
});
} catch (error) {
console.error("Failed to initiate password update:", error);
throw error;
}
};