-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BarClerk-551] - [FE] Implement Route Protection (#9)
- Loading branch information
1 parent
df036e8
commit 883956a
Showing
6 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,43 @@ | ||
## BARCLERK | ||
### API | ||
- https://barclerk.herokuapp.com/api | ||
### Client: | ||
- https://barclerk.vercel.app | ||
## BARCLERK | ||
# Description | ||
|
||
This tool/application aims to solve problems faced by legal practitioners in Western Australia particularly when it comes to matters from Legal Aid. Such problems include tracking the list of all the matters from Legal Aid, as well as billing. | ||
|
||
## 🔗 Links | ||
|
||
- Client :: https://barclerk.vercel.app | ||
- Server :: https://barclerk.herokuapp.com/api | ||
|
||
## Developers | ||
|
||
- [@AJ](https://github.com/abduljalilpalala) | ||
- [@John](https://github.com/johnpaul-sun) | ||
- [@Joshua](https://github.com/jsvelte) | ||
|
||
## Quality Assurance | ||
|
||
- [@AJ](https://github.com/abduljalilpalala) | ||
- [@John](https://github.com/johnpaul-sun) | ||
- [@Joshua](https://github.com/jsvelte) | ||
|
||
## License | ||
|
||
[![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://github.com/tterb/atomic-design-ui/blob/master/LICENSEs) | ||
[![AGPL License](https://img.shields.io/badge/license-AGPL-blue.svg)](http://www.gnu.org/licenses/agpl-3.0) | ||
[![GPLv3 License](https://img.shields.io/badge/License-GPL%20v3-yellow.svg)](https://opensource.org/licenses/) | ||
|
||
## Tech Stack | ||
|
||
**Client:** | ||
- Next.js | ||
- Redux Toolkit | ||
- Redux Thunk | ||
- TailwindCSS | ||
|
||
**Server:** | ||
- Laravel | ||
- MySQL | ||
|
||
## Appendix | ||
|
||
Any additional information goes here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { GetServerSideProps } from 'next'; | ||
|
||
import { setAuth } from 'redux/auth/authSlice'; | ||
import { wrapper } from 'redux/store'; | ||
import { axios } from 'shared/lib/axios'; | ||
|
||
export const SignInUpAuthChecker: GetServerSideProps = | ||
wrapper.getServerSideProps((store) => async ({ req }) => { | ||
const token = req.cookies['token']; | ||
const config = { headers: { Authorization: `Bearer ${token}` } }; | ||
|
||
try { | ||
const res = await axios.get('/auth', config); | ||
|
||
if (res.data) { | ||
store.dispatch(setAuth(res.data)); | ||
|
||
return { | ||
redirect: { | ||
permanent: false, | ||
destination: '/', | ||
}, | ||
props: req, | ||
}; | ||
} | ||
} catch (error: any) {} | ||
|
||
return { | ||
props: {}, | ||
}; | ||
}); | ||
|
||
export const authCheck: GetServerSideProps = wrapper.getServerSideProps( | ||
(store) => | ||
async ({ req, params }) => { | ||
const token = req.cookies['token']; | ||
const config = { headers: { Authorization: `Bearer ${token}` } }; | ||
|
||
try { | ||
const res = await axios.get('/auth', config); | ||
store.dispatch(setAuth(res.data)); | ||
|
||
const forgotPasswordPage = req.url?.includes('forgot-password'); | ||
const linkClicked = | ||
req.url?.includes('user') && req.url?.includes('verified'); | ||
|
||
if (forgotPasswordPage) { | ||
if (!token) return { props: {} }; | ||
if (linkClicked) return { props: {} }; | ||
|
||
return { | ||
redirect: { | ||
permanent: false, | ||
destination: '/', | ||
}, | ||
}; | ||
} | ||
} catch (error: any) { | ||
const forgotPasswordPage = req.url?.includes('forgot-password'); | ||
|
||
if (forgotPasswordPage) return { props: {} }; | ||
if (error.response.status === 404) { | ||
return { | ||
notFound: true, | ||
}; | ||
} | ||
if (error.response.status === 500) { | ||
throw new Error('Internal Server Error'); | ||
} | ||
return { | ||
redirect: { | ||
permanent: false, | ||
destination: '/sign-in', | ||
}, | ||
props: {}, | ||
}; | ||
} | ||
|
||
return { | ||
props: {}, | ||
}; | ||
} | ||
); |