Skip to content

Commit

Permalink
Feat: added logout if app id doesnt match (#244)
Browse files Browse the repository at this point in the history

* feat: added check for app id for auth
  • Loading branch information
prtkjakhar authored Apr 18, 2024
1 parent 5eadc43 commit 2d2a22d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 48 deletions.
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
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.

0 comments on commit 2d2a22d

Please sign in to comment.