{"version":3,"file":"SessionService.WH3f7Aoh.js","sources":["../../../../../../app/services/SessionService.ts"],"sourcesContent":["import type { Login } from \"@/models/Login\";\nimport LoginResult from \"@/models/LoginResult\";\nimport { ErrorCode } from \"~/enum/ErrorCode\";\nimport ErrorMessages from \"~/helpers/ErrorMessages\";\nimport { useRegistrationStore } from \"~/stores/registrationStore\";\nimport { navigateTo } from \"nuxt/app\";\nimport { useLinkAccountStore } from \"~/stores/linkAccountStore\";\nimport { useConfigurationStore } from \"~/stores/configurationStore\";\nimport { createSnackbarNotification } from \"@frontiers/brink-ui\";\nimport { useJourneyConfigurationStore } from \"~/stores/journeyConfigurationStore\";\nimport { UserJourneyService } from \"~/services/UserJourneyService\";\n\nexport class SessionService {\n public static async Login(login: Login): Promise {\n let maintainLoginIsLoading = false;\n const registrationStore = useRegistrationStore();\n const linkAccountStore = useLinkAccountStore();\n try {\n const response = await fetch(\"/api/onboarding-ui/v1/session/login\", {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify(login)\n });\n\n if (response.ok) {\n const loginResult = new LoginResult(await response.json());\n if (loginResult.LoginResultAction == \"1\") {\n if (loginResult.returnUrl) {\n maintainLoginIsLoading = true;\n navigateTo(loginResult.returnUrl, { external: true });\n } else {\n throw new Error(\"No returnUrl found.\");\n }\n }\n }\n else {\n const errorResult = await response.json();\n const errorCode = errorResult.Code;\n\n if (errorCode == ErrorCode.AccountInactiveOrNotVerified) {\n const userJourney = await UserJourneyService.getUserJourneyByUserId(errorResult.Data.UserId);\n if (userJourney?.journeyId && userJourney.journeyId > 0) {\n const journeyConfigurationStore = useJourneyConfigurationStore();\n await journeyConfigurationStore.fetchData(userJourney.journeyId);\n }\n registrationStore.verificationEmail = login.email;\n navigateTo(\"/register/code-validation\");\n }\n else if (errorCode == ErrorCode.UserNotLinkedToTenant) {\n const loginAuthenticationToken = errorResult.Data.LoginAuthenticationToken;\n linkAccountStore.setLoginAuthenticationToken(loginAuthenticationToken);\n navigateTo(\"/register/link-account\");\n }\n else {\n const errorMessage = ErrorMessages.getMessage(errorCode);\n if (errorCode === ErrorCode.UserSuspended) {\n const configurationStore = useConfigurationStore();\n const configuration = configurationStore.config;\n createSnackbarNotification({\n message: errorMessage,\n type: \"error\",\n autoDismiss: true,\n showCloseIcon: true,\n actionLabel: \"Contact support team\",\n onActionClick: () => {\n window.location.href = `mailto:${configuration.domainProperties.supportEmail}`;\n }\n });\n }\n else {\n createSnackbarNotification({\n message: errorMessage,\n type: \"error\",\n autoDismiss: true,\n showCloseIcon: true\n });\n }\n }\n }\n return maintainLoginIsLoading;\n } catch (e) {\n console.error(\"Error posting login: \" + e);\n throw e;\n }\n }\n\n public static async getUserId(): Promise {\n try {\n const response = await fetch(\"/api/onboarding-ui/v1/session/userId\");\n if (response.ok) {\n const userId = await response.text();\n return userId;\n }\n else {\n const errorResult = await response.json();\n const errorMsg = errorResult.Message;\n throw new Error(errorMsg);\n }\n } catch (e) {\n console.warn(\"UserId could not be retrieved: \" + e);\n return undefined;\n }\n }\n\n public static async Logout(returnUrl: string | null) {\n try {\n var path = '/api/onboarding-ui/v1/session/logout';\n\n if (returnUrl != null) {\n path = path + '?returnUrl=' + returnUrl\n }\n\n const response = await fetch(path, {\n method: \"GET\"\n });\n\n if (response.ok) {\n const logoutUrl = await response.text();\n navigateTo(logoutUrl, { external: true });\n }\n else {\n }\n } catch (e) {\n console.error(\"Error posting login: \" + e);\n throw e;\n }\n }\n}"],"names":["SessionService","login","maintainLoginIsLoading","registrationStore","useRegistrationStore","linkAccountStore","useLinkAccountStore","response","loginResult","LoginResult","navigateTo","errorResult","errorCode","ErrorCode","userJourney","UserJourneyService","useJourneyConfigurationStore","loginAuthenticationToken","errorMessage","ErrorMessages","configuration","useConfigurationStore","createSnackbarNotification","e","errorMsg","returnUrl","path","logoutUrl"],"mappings":"kTAYO,MAAMA,CAAe,CACxB,aAAoB,MAAMC,EAAgC,CACtD,IAAIC,EAAyB,GAC7B,MAAMC,EAAo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