added total monthly expenditure
This commit is contained in:
@@ -2,6 +2,7 @@ import NextAuth, { NextAuthConfig } from 'next-auth';
|
||||
import GoogleProvider from 'next-auth/providers/google';
|
||||
import { Session } from 'next-auth';
|
||||
import { AuthenticatedUser } from './types/next-auth';
|
||||
import { BillingLocation } from './db-types';
|
||||
|
||||
const authConfig: NextAuthConfig = {
|
||||
callbacks: {
|
||||
@@ -48,7 +49,18 @@ const authConfig: NextAuthConfig = {
|
||||
|
||||
export const { auth, handlers: { GET, POST } } = NextAuth(authConfig);
|
||||
|
||||
export const withUser = (fn: (user: AuthenticatedUser, ...args:any) => Promise<any>) => async (...args:any) => {
|
||||
export type AuthErrorMessage = {
|
||||
message: string,
|
||||
errors: {
|
||||
message: string,
|
||||
}
|
||||
}
|
||||
|
||||
export const isAuthErrorMessage = (obj: any): obj is AuthErrorMessage => {
|
||||
return (obj.message && obj.errors && obj.errors.message);
|
||||
}
|
||||
|
||||
export const withUser = (fn: (user: AuthenticatedUser, ...args:any) => Promise<Array<BillingLocation>>) => async (...args:any) => {
|
||||
const session = await auth();
|
||||
|
||||
if(!session) {
|
||||
@@ -57,7 +69,7 @@ export const withUser = (fn: (user: AuthenticatedUser, ...args:any) => Promise<a
|
||||
message: "Not authenticated",
|
||||
},
|
||||
message: "Not authenticated",
|
||||
});
|
||||
} as AuthErrorMessage);
|
||||
}
|
||||
const { user } = session;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user