Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: added logout if app id doesnt match #244

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions apps/amakrushi/src/components/HomePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,13 @@ const HomePage: NextPage = () => {
width: '100%',
maxWidth: '500px',
}}>
<div className={styles.imgBtn} onClick={() => {
sendMessage(t('label.weather_advisory'));
}}>
<p>{t('label.weather_advisory')}</p>
<div className={styles.imgBtn} onClick={() => { context?.setKaliaClicked((props: boolean) => !props); }}>
<p>{t('label.kalia_status')}</p>
<Image
src={weatherAdvisoryImg}
width={50}
height={70}
alt="weatheradvisory"
src={kaliaStatusImg}
width={80}
height={80}
alt="kaliastatus"
/>
</div>
<div className={styles.imgBtn} onClick={() => {
Expand All @@ -398,15 +396,17 @@ const HomePage: NextPage = () => {
/>
</div>
</div>
{/* <div className={styles.imgBtn} onClick={() => { context?.setKaliaClicked((props: boolean) => !props); }}>
<p>{t('label.kalia_status')}</p>
<div className={styles.imgBtn} style={{ marginTop: '20px' }} onClick={() => {
sendMessage(t('label.weather_advisory'));
}}>
<p>{t('label.weather_advisory')}</p>
<Image
src={kaliaStatusImg}
width={80}
height={80}
alt="kaliastatus"
src={weatherAdvisoryImg}
width={50}
height={70}
alt="weatheradvisory"
/>
</div> */}
</div>
</div>
<div className={styles.voiceRecorder} ref={voiceRecorderRef}>
<RenderVoiceRecorder setInputMsg={setInputMsg} tapToSpeak={true} includeDiv={true} />
Expand Down
2 changes: 1 addition & 1 deletion apps/amakrushi/src/components/MorePage/FAQPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const FAQPage: React.FC = () => {
const link: any = flags?.[`manual_pdf_link`]?.value;
const proxyUrl = 'https://cors-anywhere.herokuapp.com/';

window.open(link);
// window.open(link);

fetch(proxyUrl + link, {
method: 'GET',
Expand Down
1 change: 1 addition & 0 deletions apps/amakrushi/src/components/OTPpage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const OTPpage: React.FC = () => {
logEvent(analytics, 'console_error', {
error_message: err.message,
});
toast.error(`${t("message.no_link")}`);
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const RenderVoiceRecorder = ({ setInputMsg, tapToSpeak, includeDiv = false }) =>
formData.append('phoneNumber', localStorage.getItem('phoneNumber'));

// Send the WAV data to the API
const resp = await fetch(apiEndpoint + `/aitools/asr?language=${localStorage.getItem('locale')}`, {
const resp = await fetch(apiEndpoint + `/aitools/asr?language=${localStorage.getItem('locale') || 'or'}`, {
method: 'POST',
body: formData,
});
Expand Down
73 changes: 42 additions & 31 deletions apps/amakrushi/src/hooks/useLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,53 @@ export const useLogin = () => {
// No need to check for auth if access token is not present
if (cookies.access_token) {
const decodedToken: any = jwt.decode(cookies.access_token);
const expires = new Date(decodedToken?.exp * 1000);
// if token not expired then check for auth
if (expires > new Date()) {
const token = cookies.access_token;
axios
.get(`/api/auth?token=${token}`)
.then((response) => {
if (response.data === null) {
toast.error('Invalid Access Token');
removeCookie('access_token', { path: '/' });
localStorage.clear();
sessionStorage.clear();
router.push('/login');
console.log('response null');
} else {
setIsAuthenticated(true);
console.log('authenticated true');
}
})
.catch((err) => {
//@ts-ignore
logEvent(analytics, 'console_error', {
error_message: err.message,
});
removeCookie('access_token', { path: '/' });
localStorage.clear();
sessionStorage.clear();
router.push('/login');
console.log('catch err');
});
} else {
if (
decodedToken.applicationId !==
process.env.NEXT_PUBLIC_USER_SERVICE_APP_ID
) {
removeCookie('access_token', { path: '/' });
localStorage.clear();
sessionStorage.clear();
router.push('/login');
if (typeof window !== 'undefined') window.location.reload();
} else {
const expires = new Date(decodedToken?.exp * 1000);
// if token not expired then check for auth
if (expires > new Date()) {
const token = cookies.access_token;
axios
.get(`/api/auth?token=${token}`)
.then((response) => {
if (response.data === null) {
toast.error('Invalid Access Token');
removeCookie('access_token', { path: '/' });
localStorage.clear();
sessionStorage.clear();
router.push('/login');
console.log('response null');
} else {
setIsAuthenticated(true);
console.log('authenticated true');
}
})
.catch((err) => {
//@ts-ignore
logEvent(analytics, 'console_error', {
error_message: err.message,
});
removeCookie('access_token', { path: '/' });
localStorage.clear();
sessionStorage.clear();
router.push('/login');
console.log('catch err');
});
} else {
removeCookie('access_token', { path: '/' });
localStorage.clear();
sessionStorage.clear();
router.push('/login');
if (typeof window !== 'undefined') window.location.reload();
}
}
}
}, [cookies.access_token, removeCookie, router]);
Expand Down
2 changes: 1 addition & 1 deletion packages/chat-ui/dist/index.js

Large diffs are not rendered by default.