hiyaryan / the-cdj

The Cognitive Distortion Journal (CDJ) is a smart journaling tool that helps remedy distorted thinking. It can feel impossible to follow the CBT technique of labeling distorted thinking and finding alternative modes of thought (i.e. reframing) while cognitive distortions are occurring. The CDJ does that work for you. -- The CDJ is in beta testing!!
https://thecdj.app
3 stars 0 forks source link

Add frontend authorization. #14

Closed hiyaryan closed 9 months ago

hiyaryan commented 9 months ago

Adds frontend authorization to ensure users only have access to their data and must be logged in or logged out to to have access to various actions such as Logout and Login, respectively.

hiyaryan commented 9 months ago

Uses context to use journalId across React app. If there is a journalId a user has signed in or registered. This means that they have access to the full scope of the react app besides login and registration routes.

Note that if the user updates the url directly, the journal context is refreshed and they must log in again. It might be useful to use local storage instead to store the journal id as opposed to context if at some point users want to use the url to navigate.

Additionally, this PR adds a an API layer to the react app where all API calls are made as opposed to being made within each component itself such as in their useEffect hooks. This is done using two new custom hooks useEntries for all things entries related and useAccess for all things access related such as login, register, and logout.