initialise user and dbUser objects within getContext so they load per request
This commit is contained in:
@@ -102,6 +102,8 @@ npx prisma generate
|
||||
- team invitation thingy (not required, admins can add new members to team)
|
||||
- actions which mutate the current user account should update the context... (done)
|
||||
- integration with stripe including web hooks.
|
||||
-- add email to user record... capture from login same as user name
|
||||
-- add a pricing page....should be the default redirect from signup if the user has no active plan.. not sure whether to use a 'blank' plan or make plan nullable
|
||||
|
||||
# Admin Functions Scenario (shitty test)
|
||||
Pre-condition
|
||||
|
||||
@@ -8,10 +8,11 @@ import UserAccountService, { FullDBUser } from '~~/lib/services/user.account.ser
|
||||
|
||||
let prisma: PrismaClient | undefined
|
||||
let supabase: SupabaseClient | undefined
|
||||
let user: User | null;
|
||||
let dbUser: FullDBUser | null
|
||||
|
||||
export async function createContext(event: H3Event){
|
||||
let user: User | null = null;
|
||||
let dbUser: FullDBUser | null = null;
|
||||
|
||||
if (!supabase) {
|
||||
supabase = serverSupabaseClient(event)
|
||||
}
|
||||
|
||||
@@ -16,10 +16,6 @@ export const userAccountRouter = router({
|
||||
const uaService = new UserAccountService(ctx.prisma);
|
||||
const account = await uaService.changeAccountPlan(input.account_id, input.plan_id);
|
||||
|
||||
if(account){
|
||||
ctx.dbUser.memberships = ctx.dbUser.memberships.map(m => m.account_id !== account.id ? m : { ...m, account });
|
||||
}
|
||||
|
||||
return {
|
||||
account,
|
||||
}
|
||||
@@ -39,10 +35,6 @@ export const userAccountRouter = router({
|
||||
const uaService = new UserAccountService(ctx.prisma);
|
||||
const membership = await uaService.changeUserAccessWithinAccount(input.user_id, input.account_id, input.access);
|
||||
|
||||
if(membership && ctx.dbUser?.id == input.user_id){
|
||||
ctx.dbUser.memberships = ctx.dbUser.memberships.map(m => m.id !== membership.id ? m : membership);
|
||||
}
|
||||
|
||||
return {
|
||||
membership,
|
||||
}
|
||||
@@ -52,10 +44,6 @@ export const userAccountRouter = router({
|
||||
.query(async ({ ctx, input }) => {
|
||||
const uaService = new UserAccountService(ctx.prisma);
|
||||
const membership = await uaService.claimOwnershipOfAccount(ctx.dbUser.id, input.account_id);
|
||||
|
||||
if(membership && ctx.dbUser){
|
||||
ctx.dbUser.memberships = ctx.dbUser.memberships.map(m => m.id !== membership.id ? m : membership);
|
||||
}
|
||||
|
||||
return {
|
||||
membership,
|
||||
|
||||
Reference in New Issue
Block a user