From 81002da0c8f67dcb560261451eaa251259625ab2 Mon Sep 17 00:00:00 2001 From: sagar Date: Fri, 7 Mar 2025 19:17:56 +0530 Subject: [PATCH 1/2] fix: shiksha 2.0 auth + content list --- apps/shiksha-app/src/app/page.tsx | 3 +- mfes/content/next.config.js | 3 +- mfes/content/src/pages/content.tsx | 11 +- mfes/content/src/services/Read.ts | 5 +- mfes/content/src/services/Search.ts | 2 +- mfes/content/src/utils/AppConst/AppConst.ts | 5 + mfes/players/src/services/PlayerService.ts | 8 +- mfes/players/src/utils/url.config.ts | 2 +- mfes/registration/next.config.js | 4 +- mfes/registration/src/app/login/page.tsx | 87 +++---- .../src/app/shiksha-login/page.tsx | 240 ++++++++++++++++++ .../src/services/LoginService.tsx | 110 ++++++++ .../src/utils/AppConst/AppConst.ts | 5 + 13 files changed, 425 insertions(+), 60 deletions(-) create mode 100644 mfes/content/src/utils/AppConst/AppConst.ts create mode 100644 mfes/registration/src/app/shiksha-login/page.tsx create mode 100644 mfes/registration/src/utils/AppConst/AppConst.ts diff --git a/apps/shiksha-app/src/app/page.tsx b/apps/shiksha-app/src/app/page.tsx index 2e64eb0..629fbba 100644 --- a/apps/shiksha-app/src/app/page.tsx +++ b/apps/shiksha-app/src/app/page.tsx @@ -1,12 +1,11 @@ 'use client'; -import { useEffect, useState } from 'react'; +import { useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { CircularProgress, Box } from '@mui/material'; export default function AuthCheck() { const router = useRouter(); - const [loading, setLoading] = useState(true); const URL_CONTENT = process.env.NEXT_PUBLIC_CONTENT; const URL_LOGIN = process.env.NEXT_PUBLIC_LOGIN; diff --git a/mfes/content/next.config.js b/mfes/content/next.config.js index 2cd10b9..840c677 100644 --- a/mfes/content/next.config.js +++ b/mfes/content/next.config.js @@ -4,6 +4,7 @@ const { composePlugins, withNx } = require('@nx/next'); const PORTAL_BASE_URL = 'https://sunbird-editor.tekdinext.com'; +const basePath = process.env.NEXT_PUBLIC_ASSETS_CONTENT || '/mfe_content'; const routes = { API: { @@ -25,7 +26,7 @@ const nextConfig = { svgr: false, }, - basePath: '/mfe_content', // This should match the path set in Nginx + basePath, // This should match the path set in Nginx async rewrites() { return [ diff --git a/mfes/content/src/pages/content.tsx b/mfes/content/src/pages/content.tsx index 005345d..a4eff12 100644 --- a/mfes/content/src/pages/content.tsx +++ b/mfes/content/src/pages/content.tsx @@ -38,6 +38,7 @@ import ChevronRightIcon from '@mui/icons-material/ChevronRight'; import HelpIcon from '@mui/icons-material/Help'; import { SelectChangeEvent } from '@mui/material'; import { trackingData } from '../services/TrackingService'; +import AppConst from '../utils/AppConst/AppConst'; interface ContentItem { name: string; gradeLevel: string[]; @@ -248,7 +249,7 @@ export default function Content() { 'application/vnd.sunbird.questionset', ].includes(contentMimeType) ) { - await contentReadAPI(identifier); + // await contentReadAPI(identifier); router.push(`/player/${identifier}`); } else { const result = await hierarchyAPI(identifier); @@ -264,7 +265,7 @@ export default function Content() { setIsLoading(false); } }; - ``; + useEffect(() => { const handleScroll = () => { setShowBackToTop(window.scrollY > 300); @@ -294,7 +295,7 @@ export default function Content() { image={ item?.posterImage && item?.posterImage !== 'undefined' ? item?.posterImage - : '/assests/images/image_ver.png' + : `${AppConst.BASEPATH}/assests/images/image_ver.png` } content={item?.description || '-'} // subheader={item?.contentType} @@ -320,7 +321,7 @@ export default function Content() { {isLoading ? 'Loading...' : 'Load More'} ) : ( - + No more data available )} @@ -411,7 +412,7 @@ export default function Content() { }, [router]); const fetchFramework = async () => { try { - const url = `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/api/framework/v1/read/${process.env.NEXT_PUBLIC_FRAMEWORK}`; + const url = `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/interface/v1/api/framework/v1/read/${process.env.NEXT_PUBLIC_FRAMEWORK}`; const frameworkData = await fetch(url).then((res) => res.json()); const frameworks = frameworkData?.result?.framework; setFrameworkFilter(frameworks); diff --git a/mfes/content/src/services/Read.ts b/mfes/content/src/services/Read.ts index ddcd5d8..6b7216a 100644 --- a/mfes/content/src/services/Read.ts +++ b/mfes/content/src/services/Read.ts @@ -121,9 +121,10 @@ export const contentReadAPI = async (doId: string) => { const config: AxiosRequestConfig = { method: 'get', maxBodyLength: Infinity, - url: `${searchApiUrl}/api/content/v1/read/` + doId, + url: `${searchApiUrl}/interface/v1/action/content/v3/read/` + doId, headers: { - Authorization: `'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0WEZYTWFVOWFBanpUbk5aSXNySEpyV0hwVW94bzY3NyJ9.WSWVtVh5MCH_yymFEM_qpVzXGdDO5mukrqmIii1C5Ww'`, + tenantId: localStorage.getItem('tenantId') || '', + Authorization: `Bearer ${localStorage.getItem('accToken') || ''}`, }, }; console.log('config', config); diff --git a/mfes/content/src/services/Search.ts b/mfes/content/src/services/Search.ts index 45f51f5..96d4320 100644 --- a/mfes/content/src/services/Search.ts +++ b/mfes/content/src/services/Search.ts @@ -155,7 +155,7 @@ export const ContentSearch = async ( const config: AxiosRequestConfig = { method: 'post', maxBodyLength: Infinity, - url: `${searchApiUrl}/api/content/v1/search`, + url: `${searchApiUrl}/interface/v1/action/composite/v3/search`, data: data, }; diff --git a/mfes/content/src/utils/AppConst/AppConst.ts b/mfes/content/src/utils/AppConst/AppConst.ts new file mode 100644 index 0000000..62267e1 --- /dev/null +++ b/mfes/content/src/utils/AppConst/AppConst.ts @@ -0,0 +1,5 @@ +const AppConst = { + BASEPATH: process.env.NEXT_PUBLIC_ASSETS_CONTENT || '/mfe_content', +}; + +export default AppConst; diff --git a/mfes/players/src/services/PlayerService.ts b/mfes/players/src/services/PlayerService.ts index 1bcd3b4..b939ca2 100644 --- a/mfes/players/src/services/PlayerService.ts +++ b/mfes/players/src/services/PlayerService.ts @@ -9,7 +9,13 @@ export const fetchContent = async (identifier: any) => { const LICENSE_DETAILS = URL_CONFIG.PARAMS.LICENSE_DETAILS; const MODE = 'edit'; const response = await axios.get( - `${API_URL}?fields=${FIELDS}&mode=${MODE}&licenseDetails=${LICENSE_DETAILS}` + `${API_URL}?fields=${FIELDS}&mode=${MODE}&licenseDetails=${LICENSE_DETAILS}`, + { + headers: { + tenantId: localStorage.getItem('tenantId') || '', + Authorization: `Bearer ${localStorage.getItem('accToken') || ''}`, + }, + } ); console.log('response =====>', response); return response?.data?.result?.content; diff --git a/mfes/players/src/utils/url.config.ts b/mfes/players/src/utils/url.config.ts index 276c4eb..d3395ed 100644 --- a/mfes/players/src/utils/url.config.ts +++ b/mfes/players/src/utils/url.config.ts @@ -6,7 +6,7 @@ export const URL_CONFIG = { HIERARCHY_FEILDS: 'instructions,outcomeDeclaration', }, API: { - CONTENT_READ: `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/api/content/v1/read/`, + CONTENT_READ: `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/interface/v1/action/content/v3/read/`, HIERARCHY_API: `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/action/questionset/v2/hierarchy/`, QUESTIONSET_READ: `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/action/questionset/v2/read/`, COMPOSITE_SEARCH: `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/action/composite/v3/search`, diff --git a/mfes/registration/next.config.js b/mfes/registration/next.config.js index cc6a55d..7f34632 100644 --- a/mfes/registration/next.config.js +++ b/mfes/registration/next.config.js @@ -2,6 +2,8 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires const { composePlugins, withNx } = require('@nx/next'); +const BASE_PATH = + process.env.NEXT_PUBLIC_ASSETS_REGISTRATION || '/mfe_registration'; /** * @type {import('@nx/next/plugins/with-nx').WithNxOptions} @@ -13,7 +15,7 @@ const nextConfig = { svgr: false, }, - basePath: '/mfe_registration', // This should match the path set in Nginx + basePath: BASE_PATH, // This should match the path set in Nginx }; const plugins = [ diff --git a/mfes/registration/src/app/login/page.tsx b/mfes/registration/src/app/login/page.tsx index 9ca35cf..e1a52dd 100644 --- a/mfes/registration/src/app/login/page.tsx +++ b/mfes/registration/src/app/login/page.tsx @@ -1,30 +1,17 @@ 'use client'; -import React, { useState } from 'react'; -import { Button, Typography } from '@mui/material'; import VisibilityIcon from '@mui/icons-material/Visibility'; import VisibilityOffIcon from '@mui/icons-material/VisibilityOff'; +import { AlertTitle, Button } from '@mui/material'; import Alert from '@mui/material/Alert'; import CircularProgress from '@mui/material/CircularProgress'; import Grid from '@mui/material/Grid2'; -import { - CommonCheckbox, - CommonSelect, - CommonTextField, - Layout, - // login, -} from '@shared-lib'; -import { SelectChangeEvent } from '@mui/material/Select'; -import Link from 'next/link'; -import { getToken } from '../../services/LoginService'; -import { useRouter } from 'next/navigation'; +// import { SelectChangeEvent } from '@mui/material/Select'; +import { CommonTextField, Layout } from '@shared-lib'; import { jwtDecode } from 'jwt-decode'; -const languageData = [ - { id: 1, name: 'English' }, - { id: 2, name: 'Marathi' }, - { id: 3, name: 'Hindi' }, -]; - -const checkboxData = [{ label: 'Remember Me' }]; +import { useRouter } from 'next/navigation'; +import React, { useState } from 'react'; +import { login } from '../../services/LoginService'; +import AppConst from '../../utils/AppConst/AppConst'; export default function Login() { const [formData, setFormData] = useState({ @@ -35,11 +22,10 @@ export default function Login() { userName: false, password: false, }); - const [selectedValue, setSelectedValue] = useState('english'); - const [checked, setChecked] = useState(false); + // const [selectedValue, setSelectedValue] = useState('english'); + // const [checked, setChecked] = useState(false); const [showPassword, setShowPassword] = useState(false); - const [showError, setShowError] = useState(false); - const [errorMessage, setErrorMessage] = useState(''); + const [errorMessage, setErrorMessage] = useState([]); const [loading, setLoading] = useState(false); const router = useRouter(); const handleChange = @@ -55,16 +41,16 @@ export default function Login() { }); }; - const handleCheckboxChange = ( - event: React.ChangeEvent, - checked: boolean, - label: string - ) => { - setChecked(checked); - console.log( - `Checkbox '${label}' is now ${checked ? 'checked' : 'unchecked'}` - ); - }; + // const handleCheckboxChange = ( + // event: React.ChangeEvent, + // checked: boolean, + // label: string + // ) => { + // setChecked(checked); + // console.log( + // `Checkbox '${label}' is now ${checked ? 'checked' : 'unchecked'}` + // ); + // }; const handleButtonClick = async () => { if (!formData.userName || !formData.password) { @@ -76,14 +62,15 @@ export default function Login() { } setLoading(true); try { - const response = await getToken({ + const { result: response, authUser } = await login({ username: formData.userName, password: formData.password, }); - if (response?.access_token) { + if (response?.access_token && authUser?.tenantData?.[0]?.tenantId) { localStorage.setItem('accToken', response?.access_token); localStorage.setItem('refToken', response?.refresh_token); + localStorage.setItem('tenantId', authUser?.tenantData?.[0]?.tenantId); const decoded = jwtDecode(response?.access_token); const subId = decoded?.sub?.split(':')[2]; document.cookie = `subid=${subId}; path=/;`; @@ -92,21 +79,23 @@ export default function Login() { router.push(redirectUrl); } } else { - setShowError(true); - setErrorMessage(response); + if (!response?.access_token) { + setErrorMessage(['Invalid tenantId or access token']); + } else if (!authUser?.tenantData?.[0]?.tenantId) { + setErrorMessage(['Invalid tenantId']); + } } } catch (error: any) { console.error('Login failed:', error); - setShowError(true); - setErrorMessage(error); + setErrorMessage([error.message, error?.response?.data?.params?.errmsg]); } finally { setLoading(false); } }; - const handleSelectChange = (event: SelectChangeEvent) => { - setSelectedValue(event.target.value); - }; + // const handleSelectChange = (event: SelectChangeEvent) => { + // setSelectedValue(event.target.value); + // }; return ( Company Logo @@ -157,6 +146,7 @@ export default function Login() { padding: '15px', backgroundColor: '#FFFFFF', }} + justifyContent={{ sm: 'center', md: 'center' }} > {/* */} - {showError && ( + {Array.isArray(errorMessage) && errorMessage.length > 0 && ( - {errorMessage} + Error +
    + {errorMessage.map((error) => ( +
  • {error}
  • + ))} +
)}
diff --git a/mfes/registration/src/app/shiksha-login/page.tsx b/mfes/registration/src/app/shiksha-login/page.tsx new file mode 100644 index 0000000..f03e27c --- /dev/null +++ b/mfes/registration/src/app/shiksha-login/page.tsx @@ -0,0 +1,240 @@ +'use client'; +import VisibilityIcon from '@mui/icons-material/Visibility'; +import VisibilityOffIcon from '@mui/icons-material/VisibilityOff'; +import { Button } from '@mui/material'; +import Alert from '@mui/material/Alert'; +import CircularProgress from '@mui/material/CircularProgress'; +import Grid from '@mui/material/Grid2'; +// import { SelectChangeEvent } from '@mui/material/Select'; +import { CommonTextField, Layout } from '@shared-lib'; +import { jwtDecode } from 'jwt-decode'; +import { useRouter } from 'next/navigation'; +import React, { useState } from 'react'; +import { getToken } from '../../services/LoginService'; +import AppConst from '../../utils/AppConst/AppConst'; + +export default function Login() { + const [formData, setFormData] = useState({ + userName: '', + password: '', + }); + const [error, setError] = useState({ + userName: false, + password: false, + }); + // const [selectedValue, setSelectedValue] = useState('english'); + // const [checked, setChecked] = useState(false); + const [showPassword, setShowPassword] = useState(false); + const [showError, setShowError] = useState(false); + const [errorMessage, setErrorMessage] = useState(''); + const [loading, setLoading] = useState(false); + const router = useRouter(); + const handleChange = + (field: string) => (event: React.ChangeEvent) => { + const value = event.target.value; + setFormData({ + ...formData, + [field]: value, + }); + setError({ + ...error, + [field]: value.trim() === '', + }); + }; + + // const handleCheckboxChange = ( + // event: React.ChangeEvent, + // checked: boolean, + // label: string + // ) => { + // setChecked(checked); + // console.log( + // `Checkbox '${label}' is now ${checked ? 'checked' : 'unchecked'}` + // ); + // }; + + const handleButtonClick = async () => { + if (!formData.userName || !formData.password) { + setError({ + userName: !formData.userName, + password: !formData.password, + }); + return; + } + setLoading(true); + try { + const response = await getToken({ + username: formData.userName, + password: formData.password, + }); + + if (response?.access_token) { + localStorage.setItem('accToken', response?.access_token); + localStorage.setItem('refToken', response?.refresh_token); + const decoded = jwtDecode(response?.access_token); + const subId = decoded?.sub?.split(':')[2]; + document.cookie = `subid=${subId}; path=/;`; + const redirectUrl = process.env.NEXT_PUBLIC_CONTENT; + if (redirectUrl) { + router.push(redirectUrl); + } + } else { + setShowError(true); + setErrorMessage(response); + } + } catch (error: any) { + console.error('Login failed:', error); + setShowError(true); + setErrorMessage(error); + } finally { + setLoading(false); + } + }; + + // const handleSelectChange = (event: SelectChangeEvent) => { + // setSelectedValue(event.target.value); + // }; + + return ( + + + + + Company Logo + + + + + {/* ({ + label: name, + value: name.toLowerCase(), + }))} + width="100px" + height="32px" + borderRadius="8px" + /> */} + + setShowPassword(!showPassword)} + style={{ cursor: 'pointer' }} + /> + ) : ( + setShowPassword(!showPassword)} + style={{ cursor: 'pointer' }} + /> + ), + }} + /> + {/* + Forgot Password? + + + */} + + + {/* + Don’t Have An Account? Register + */} + + + {showError && ( + + {errorMessage} + + )} + + ); +} diff --git a/mfes/registration/src/services/LoginService.tsx b/mfes/registration/src/services/LoginService.tsx index 8ac1f4a..6f78c2a 100644 --- a/mfes/registration/src/services/LoginService.tsx +++ b/mfes/registration/src/services/LoginService.tsx @@ -1,3 +1,4 @@ +import { post, get } from '@shared-lib'; import axios from 'axios'; interface LoginParams { username: string; @@ -29,3 +30,112 @@ export const getToken = async ({ username, password }: LoginParams) => { return error?.response?.data?.error_description; } }; + +interface RefreshParams { + refresh_token: string; +} + +export const login = async ({ + username, + password, +}: LoginParams): Promise => { + const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/auth/login`; + + try { + const response = await post(apiUrl, { username, password }); + const response2 = await axios.get( + `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/auth`, + { + headers: { + Authorization: `Bearer ${response?.data?.result?.access_token}`, + }, + withCredentials: true, + } + ); + return { ...response?.data, authUser: response2?.data?.result }; + } catch (error) { + console.error('error in login', error); + throw error; + } +}; + +export const refresh = async ({ + refresh_token, +}: RefreshParams): Promise => { + const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/auth/refresh`; + try { + const response = await post(apiUrl, { refresh_token }); + return response?.data; + } catch (error) { + console.error('error in login', error); + throw error; + } +}; + +export const logout = async (refreshToken: string): Promise => { + const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/auth/logout`; + try { + const response = await post(apiUrl, { refresh_token: refreshToken }); + return response; + } catch (error) { + console.error('error in logout', error); + throw error; + } +}; + +export const resetPassword = async (newPassword: any): Promise => { + const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/reset-password`; + try { + const response = await post(apiUrl, { newPassword }); + return response?.data; + } catch (error) { + console.error('error in reset', error); + throw error; + } +}; + +export const forgotPasswordAPI = async ( + newPassword: any, + token: any +): Promise => { + const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/forgot-password`; + try { + const response = await post(apiUrl, { newPassword, token }); + return response?.data; + } catch (error) { + console.error('error in reset', error); + throw error; + } +}; + +export const resetPasswordLink = async (username: any): Promise => { + const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/password-reset-link`; + try { + let redirectUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || ''; + if (redirectUrl === '' && typeof window !== 'undefined') { + redirectUrl = window.location.origin; + } + const response = await post(apiUrl, { username, redirectUrl }); + return response?.data; + } catch (error) { + console.error('error in reset', error); + throw error; + } +}; + +// export const successfulNotification = async ( +// isQueue:boolean, +// context: any, +// key: any, +// email: any +// ): Promise => { +// const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/notification/send`; +// try { +// const response = await post(apiUrl, { isQueue, context, key, email }); +// console.log(email); +// return response?.data; +// } catch (error) { +// console.error('error in reset', error); +// throw error; +// } +// }; diff --git a/mfes/registration/src/utils/AppConst/AppConst.ts b/mfes/registration/src/utils/AppConst/AppConst.ts new file mode 100644 index 0000000..b13e55f --- /dev/null +++ b/mfes/registration/src/utils/AppConst/AppConst.ts @@ -0,0 +1,5 @@ +const AppConst = { + BASEPATH: process.env.NEXT_PUBLIC_ASSETS_REGISTRATION || '/mfe_registration', +}; + +export default AppConst; From 67dec1977db61a2bc4b4b8a125b3b3753b5de106 Mon Sep 17 00:00:00 2001 From: sagar Date: Fri, 7 Mar 2025 19:35:48 +0530 Subject: [PATCH 2/2] fix: save framework, tenant-code and tenantId in local storage and use in API --- mfes/content/src/pages/content.tsx | 6 ++++- mfes/content/src/services/Search.ts | 1 + mfes/registration/src/app/login/page.tsx | 29 +++++++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/mfes/content/src/pages/content.tsx b/mfes/content/src/pages/content.tsx index a4eff12..dbba771 100644 --- a/mfes/content/src/pages/content.tsx +++ b/mfes/content/src/pages/content.tsx @@ -412,7 +412,11 @@ export default function Content() { }, [router]); const fetchFramework = async () => { try { - const url = `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/interface/v1/api/framework/v1/read/${process.env.NEXT_PUBLIC_FRAMEWORK}`; + const url = `${ + process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL + }/interface/v1/api/framework/v1/read/${ + localStorage.getItem('framework') || process.env.NEXT_PUBLIC_FRAMEWORK + }`; const frameworkData = await fetch(url).then((res) => res.json()); const frameworks = frameworkData?.result?.framework; setFrameworkFilter(frameworks); diff --git a/mfes/content/src/services/Search.ts b/mfes/content/src/services/Search.ts index 96d4320..787fbd9 100644 --- a/mfes/content/src/services/Search.ts +++ b/mfes/content/src/services/Search.ts @@ -132,6 +132,7 @@ export const ContentSearch = async ( // channel: '0135656861912678406', primaryCategory: [type], + channel: localStorage.getItem('tenant-code'), }, fields: [ 'name', diff --git a/mfes/registration/src/app/login/page.tsx b/mfes/registration/src/app/login/page.tsx index e1a52dd..a743fd4 100644 --- a/mfes/registration/src/app/login/page.tsx +++ b/mfes/registration/src/app/login/page.tsx @@ -13,6 +13,20 @@ import React, { useState } from 'react'; import { login } from '../../services/LoginService'; import AppConst from '../../utils/AppConst/AppConst'; +const info = [ + { + tenantId: '3a849655-30f6-4c2b-8707-315f1ed64fbd', + tenantName: 'atree', + channel: 'atree-channel', + framework: 'atree framework', + }, + { + tenantId: '6c386899-7a00-4733-8447-5ef925bbf700', + tenantName: 'Key Education Foundation', + channel: 'kef-channel', + framework: 'kef-framework', + }, +]; export default function Login() { const [formData, setFormData] = useState({ userName: '', @@ -66,11 +80,22 @@ export default function Login() { username: formData.userName, password: formData.password, }); + const tenantInfo = info.find( + (tenant) => tenant.tenantId === authUser?.tenantData?.[0]?.tenantId + ); - if (response?.access_token && authUser?.tenantData?.[0]?.tenantId) { + if ( + response?.access_token && + authUser?.tenantData?.[0]?.tenantId && + tenantInfo + ) { localStorage.setItem('accToken', response?.access_token); localStorage.setItem('refToken', response?.refresh_token); + const { framework, channel } = tenantInfo; + localStorage.setItem('framework', framework); + localStorage.setItem('tenant-code', channel); localStorage.setItem('tenantId', authUser?.tenantData?.[0]?.tenantId); + const decoded = jwtDecode(response?.access_token); const subId = decoded?.sub?.split(':')[2]; document.cookie = `subid=${subId}; path=/;`; @@ -83,6 +108,8 @@ export default function Login() { setErrorMessage(['Invalid tenantId or access token']); } else if (!authUser?.tenantData?.[0]?.tenantId) { setErrorMessage(['Invalid tenantId']); + } else if (!tenantInfo) { + setErrorMessage(['not found tenant config']); } } } catch (error: any) {