From 5520f1ed94a769fe9a461d57f1f113aca69fec65 Mon Sep 17 00:00:00 2001 From: Lera24 Date: Fri, 17 May 2024 12:14:02 +0300 Subject: [PATCH] fix: redirect when successful authorization[WTEL-3405 --- src/store/modules/auth/auth.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/store/modules/auth/auth.js b/src/store/modules/auth/auth.js index 59573094..c7d3d52f 100644 --- a/src/store/modules/auth/auth.js +++ b/src/store/modules/auth/auth.js @@ -25,14 +25,16 @@ const actions = { SUBMIT_AUTH: async (context, action) => { let accessToken; - if(action === 'login') { - if(context.state.sessionId) { - accessToken = await context.dispatch('LOGIN_2FA'); - } - accessToken = await context.dispatch('LOGIN'); - } else if(action === 'register') { - accessToken = await context.dispatch('REGISTER'); - } else throw new Error(`Invalid action: ${action}`); + switch (action) { + case 'login': + accessToken = await context.dispatch(context.state.sessionId ? 'LOGIN_2FA' : 'LOGIN'); + break; + case 'register': + accessToken = await context.dispatch('REGISTER'); + break; + default: + throw new Error(`Invalid action: ${action}`); + } return context.dispatch('ON_AUTH_SUCCESS', { accessToken }); },