2023-02-13 12:41:30 +00:00
|
|
|
import type * as Hapi from "@hapi/hapi";
|
2023-05-26 08:27:16 +00:00
|
|
|
import NextAuthPlugin from "@digiresilience/hapi-nextauth";
|
2023-03-13 11:00:49 +00:00
|
|
|
import { NextAuthAdapter } from "@digiresilience/metamigo-common";
|
2023-03-13 14:42:49 +00:00
|
|
|
import { IAppConfig } from "@digiresilience/metamigo-config";
|
2023-02-13 12:41:30 +00:00
|
|
|
|
|
|
|
|
export const registerNextAuth = async (
|
|
|
|
|
server: Hapi.Server,
|
|
|
|
|
config: IAppConfig
|
|
|
|
|
): Promise<void> => {
|
2023-05-26 08:27:16 +00:00
|
|
|
const nextAuthAdapterFactory: any = (request: Hapi.Request) => new NextAuthAdapter(request.db());
|
2023-02-13 12:41:30 +00:00
|
|
|
|
|
|
|
|
await server.register({
|
|
|
|
|
plugin: NextAuthPlugin,
|
|
|
|
|
options: {
|
|
|
|
|
nextAuthAdapterFactory,
|
|
|
|
|
sharedSecret: config.nextAuth.secret,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|