Skip to content

Commit

Permalink
BC-7171 - TSC: Logout with open tldraw tab leads to wrong page (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
bergatco authored Dec 20, 2024
1 parent 775ae46 commit c45e1e0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/configuration/api/api.configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export const API = {
FILE_UPLOAD: "/api/v3/file/upload/school/SCHOOLID/boardnodes/CONTEXTID",
FILE_DELETE: "/api/v3/file/delete/FILERECORD_ID",
FILE_RESTORE: "/api/v3/file/restore/FILERECORD_ID",
LOGIN_REDIRECT: "/login?redirect=/tldraw?parentId=PARENTID",
USER_DATA: `/api/v3/user/me`,
CONFIG_PATH: `/api/tldraw/config/public`,
};
3 changes: 3 additions & 0 deletions src/mapper/configuration.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const checkEnvType = (obj: Record<string, unknown>): void => {
obj,
"TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST",
);
TypeGuard.checkKeyAndValueExists(obj, "NOT_AUTHENTICATED_REDIRECT_URL");
TypeGuard.checkBoolean(obj.FEATURE_TLDRAW_ENABLED);
TypeGuard.checkNumber(obj.TLDRAW_ASSETS_MAX_SIZE_BYTES);
TypeGuard.checkArray(obj.TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST);
Expand All @@ -33,6 +34,8 @@ export class ConfigurationMapper {
TLDRAW_ASSETS_MAX_SIZE_BYTES: configuration.TLDRAW_ASSETS_MAX_SIZE_BYTES,
TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST:
configuration.TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST,
NOT_AUTHENTICATED_REDIRECT_URL:
configuration.NOT_AUTHENTICATED_REDIRECT_URL,
};

return mappedConfiguration;
Expand Down
1 change: 1 addition & 0 deletions src/types/Envs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export type Envs = {
TLDRAW_ASSETS_MAX_SIZE_BYTES: number;
TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST: string[];
TLDRAW_WEBSOCKET_URL: string;
NOT_AUTHENTICATED_REDIRECT_URL: string;
};
1 change: 1 addition & 0 deletions src/utils/envConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const getEnvs = async (): Promise<Envs> => {
"image/svg+xml",
],
FEATURE_TLDRAW_ENABLED: true,
NOT_AUTHENTICATED_REDIRECT_URL: "http://localhost:4000/login",
};

return configuration;
Expand Down
17 changes: 7 additions & 10 deletions src/utils/redirectUtils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { API } from "../configuration/api/api.configuration";
import { Envs } from "../types/Envs";
import { HttpStatusCode } from "../types/StatusCodeEnums";
import { UserResult } from "../types/User";
import { setErrorData } from "./errorData";
import { validateId } from "./validator";
import { getEnvs } from "./envConfig";

const getParentId = () => {
const urlParams = new URLSearchParams(window.location.search);
Expand All @@ -14,16 +14,13 @@ const getParentId = () => {
return parentId;
};

const redirectToLoginPage = () => {
const redirectToLoginPage = async () => {
const envs = await getEnvs();
const parentId = getParentId();
if (import.meta.env.PROD) {
const redirectUrl = API.LOGIN_REDIRECT.replace("PARENTID", parentId);
window.location.assign(redirectUrl);
} else {
window.location.assign(
`http://localhost:4000/login?redirect=tldraw?parentId=${parentId}`,
);
}
let redirectUrl = envs.NOT_AUTHENTICATED_REDIRECT_URL;
const separator = redirectUrl.includes("?") ? "&" : "?";
redirectUrl += `${separator}redirect=/tldraw?parentId=${parentId}`;
window.location.assign(redirectUrl);
};

const redirectToErrorPage = () => {
Expand Down

0 comments on commit c45e1e0

Please sign in to comment.