This commit is contained in:
David Nguyen
2025-02-05 00:57:00 +11:00
parent 540cc5bfc1
commit 1057ae6d2a
105 changed files with 379 additions and 357 deletions

View File

@ -0,0 +1,31 @@
import type { AppLoadContext } from 'react-router';
import { redirect } from 'react-router';
/**
* Returns the session context or throws a redirect to signin if it is not present.
*/
export const getRequiredLoaderSession = (context: AppLoadContext) => {
if (!context.session) {
throw redirect('/signin'); // Todo: Maybe add a redirect cookie to come back?
}
return context.session;
};
/**
* Returns the team session context or throws a redirect to signin if it is not present.
*/
export const getRequiredLoaderTeamSession = (context: AppLoadContext) => {
if (!context.session) {
throw redirect('/signin'); // Todo: Maybe add a redirect cookie to come back?
}
if (!context.session.currentTeam) {
throw new Response(null, { status: 404 }); // Todo: Test that 404 page shows up.
}
return {
...context.session,
currentTeam: context.session.currentTeam,
};
};