fix: frontend build failing after code formatting library update (#21519)
Starting the frontend(`nx start twenty-front`) was failing because one of its dependencies - the client SDK - can not be built. A recent update made the sdk compatible with a newer version of Prettier. That update started using parts of prettier that the build setup did not recognize, so the build stopped with an error about a missing module. This PR updated the SDK’s build configuration, so it correctly handles those prettier imports. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/twentyhq/twenty/pull/21519?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. --> --------- Signed-off-by: Parship Chowdhury <parshipchowdhury@gmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
committed by
GitHub
parent
050f7dcf85
commit
4899f00bc7
@@ -1,30 +1,22 @@
|
||||
import { type Page } from '@playwright/test';
|
||||
|
||||
const decodeToken = (cookie: any) =>
|
||||
JSON.parse(decodeURIComponent(cookie.value)).accessOrWorkspaceAgnosticToken
|
||||
?.token;
|
||||
|
||||
const decodePayload = (jwt: string) =>
|
||||
JSON.parse(Buffer.from(jwt.split('.')[1], 'base64url').toString());
|
||||
|
||||
// Mirrors TOKEN_PAIR_LOCAL_STORAGE_KEY from twenty-front
|
||||
// (packages/twenty-front/src/modules/auth/states/tokenPairState.ts).
|
||||
// Since #21507 the frontend stores the auth token pair in localStorage
|
||||
// instead of a cookie.
|
||||
const TOKEN_PAIR_LOCAL_STORAGE_KEY = 'tokenPairState';
|
||||
|
||||
export const getAccessAuthToken = async (page: Page) => {
|
||||
const storageState = await page.context().storageState();
|
||||
const tokenCookies = storageState.cookies.filter(
|
||||
(cookie) => cookie.name === 'tokenPair',
|
||||
);
|
||||
if (!tokenCookies) {
|
||||
throw new Error('No auth cookie found');
|
||||
const tokenPairItem = storageState.origins
|
||||
.flatMap((origin) => origin.localStorage)
|
||||
.find((item) => item.name === TOKEN_PAIR_LOCAL_STORAGE_KEY);
|
||||
|
||||
if (tokenPairItem === undefined) {
|
||||
throw new Error('No auth token pair found in local storage');
|
||||
}
|
||||
const accessTokenCookie = tokenCookies.find(
|
||||
(cookie) => {
|
||||
const payload = decodePayload(decodeToken(cookie) ?? '');
|
||||
return payload.type === 'ACCESS';
|
||||
}
|
||||
);
|
||||
|
||||
const token = JSON.parse(decodeURIComponent(accessTokenCookie?.value ?? '')).accessOrWorkspaceAgnosticToken
|
||||
.token;
|
||||
const { accessOrWorkspaceAgnosticToken } = JSON.parse(tokenPairItem.value);
|
||||
|
||||
return { authToken: token };
|
||||
return { authToken: accessOrWorkspaceAgnosticToken.token };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user