mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 16:51:38 +10:00
32 lines
904 B
TypeScript
32 lines
904 B
TypeScript
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 getRequiredSessionContext = (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 getRequiredTeamSessionContext = (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,
|
|
};
|
|
};
|