Skip to content

Commit 22ca473

Browse files
WMS-30135 | fix: improve authentication handling in project sync for pulling new changes
1 parent 5667fc3 commit 22ca473

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/project-sync.service.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const MAX_REQUEST_ALLOWED_TIME = 5 * 60 * 1000;
1818
const loggerLabel = 'project-sync-service';
1919
let remoteBaseCommitId = '';
2020
let WM_PLATFORM_VERSION = '';
21+
let isAuthenticated = false;
2122

2223
async function findProjectId(config) {
2324
const projectList = (await axios.get(`${config.baseUrl}/edn-services/rest/users/projects/list`,
@@ -142,6 +143,17 @@ async function gitResetAndPull(tempDir, projectDir){
142143
}
143144

144145
async function pullChanges(projectId, config, projectDir) {
146+
isAuthenticated = await checkAuthCookie(config);
147+
148+
if (!isAuthenticated) {
149+
console.log(chalk.yellow('\n⚠ Authentication Required'));
150+
console.log(chalk.gray('━'.repeat(50)));
151+
console.log(chalk.white('\nYour session has expired. Please authenticate to continue.'));
152+
console.log(chalk.cyan(`\n→ Generate token: ${config.baseUrl}/studio/services/auth/token\n`));
153+
config.authCookie = await authenticateWithToken(config, false);
154+
global.localStorage.setItem(STORE_KEY, config.authCookie);
155+
}
156+
145157
try {
146158
const output = await exec('git', ['rev-parse', 'HEAD'], {
147159
cwd: projectDir
@@ -363,7 +375,7 @@ async function setup(previewUrl, projectName, authToken) {
363375
appPreviewUrl: previewUrl,
364376
projectName: projectName
365377
};
366-
const isAuthenticated = await checkAuthCookie(config);
378+
isAuthenticated = await checkAuthCookie(config);
367379
if (!isAuthenticated) {
368380
//console.log(`Need to login to Studio (${config.baseUrl}). \n Please enter your Studio credentails.`);
369381
//config.authCookie = await authenticateWithUserNameAndPassword(config);

0 commit comments

Comments
 (0)