diff --git a/Auth.md b/Auth.md new file mode 100644 index 000000000..7bb71b2ef --- /dev/null +++ b/Auth.md @@ -0,0 +1,13 @@ +# Auth + +The web is using OAuth 2.0 to handle auth. We host our own instance of [Curity](https://curity.io), which is our identity and access management solution. + +## Session management in Next +We use [Auth.js](https://authjs.dev) to handle everything regarding auth in the web. We use the JWT session strategy, which means that everything regarding the session is stored in a JWT, which is stored in the browser in an encrypted cookie. + +## Keeping the access token alive +When the user performs a navigation the web app often does multiple requests to Next. If the access token has expired Next will do a request to Curity to renew the tokens. Since we only allow a single refresh token to be used only once only the first request will succeed and the following requests will fail. + +To avoid that we have a component whose only purpose is to keep the access token alive. As long as no other request is happening at the same time this will work fine. + +To avoid a session that keeps on refreshing forever, if the user have the page open in the background e.g., we have a timeout that stops the refreshing if the user is not active. \ No newline at end of file diff --git a/app/[lang]/(live)/layout.tsx b/app/[lang]/(live)/layout.tsx index 2da54eb0a..35144b8d9 100644 --- a/app/[lang]/(live)/layout.tsx +++ b/app/[lang]/(live)/layout.tsx @@ -5,6 +5,7 @@ import Script from "next/script" import TrpcProvider from "@/lib/trpc/Provider" +import TokenRefresher from "@/components/Auth/TokenRefresher" import AdobeSDKScript from "@/components/Current/AdobeSDKScript" import Footer from "@/components/Current/Footer" import VwoScript from "@/components/Current/VwoScript" @@ -59,6 +60,7 @@ export default async function RootLayout({ {header} {children}