mirror of
https://github.com/documenso/documenso.git
synced 2025-11-16 17:51:49 +10:00
fix: wip
This commit is contained in:
31
apps/remix/server/utils/get-required-session-context.ts
Normal file
31
apps/remix/server/utils/get-required-session-context.ts
Normal 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 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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user