multi-user support
This commit is contained in:
@@ -1,6 +1,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';
|
||||
|
||||
const authConfig: NextAuthConfig = {
|
||||
callbacks: {
|
||||
@@ -45,4 +46,20 @@ const authConfig: NextAuthConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
export const { auth, handlers: { GET, POST } } = NextAuth(authConfig);
|
||||
export const { auth, handlers: { GET, POST } } = NextAuth(authConfig);
|
||||
|
||||
export const withUser = (fn: (user: AuthenticatedUser, ...args:any) => Promise<any>) => async (...args:any) => {
|
||||
const session = await auth();
|
||||
|
||||
if(!session) {
|
||||
return({
|
||||
errors: {
|
||||
message: "Not authenticated",
|
||||
},
|
||||
message: "Not authenticated",
|
||||
});
|
||||
}
|
||||
const { user } = session;
|
||||
|
||||
return(fn(user, ...args));
|
||||
}
|
||||
Reference in New Issue
Block a user