Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat: use custom verify token policy (#5836)

DarkSkyfd18732e6e7b
diff --git a/packages/backend/server/src/core/auth/next-auth-options.ts b/packages/backend/server/src/core/auth/next-auth-options.ts
index 3a80c2edd9..b65ed520c0 100644
--- a/packages/backend/server/src/core/auth/next-auth-options.ts
+++ b/packages/backend/server/src/core/auth/next-auth-options.ts
@@ -96,6 +96,24 @@ export const NextAuthOptionsProvider: FactoryProvider<NextAuthOptions> = {
}
return result;
};
+
+ prismaAdapter.createVerificationToken = async data => {
+ await session.set(
+ `${data.identifier}:${data.token}`,
+ Date.now() + session.sessionTtl
+ );
+ return data;
+ };
+
+ prismaAdapter.useVerificationToken = async ({ identifier, token }) => {
+ const expires = await session.get(`${identifier}:${token}`);
+ if (expires) {
+ return { identifier, token, expires: new Date(expires) };
+ } else {
+ return null;
+ }
+ };
+
const nextAuthOptions: NextAuthOptions = {
providers: [],
adapter: prismaAdapter,
diff --git a/packages/backend/server/src/fundamentals/session/index.ts b/packages/backend/server/src/fundamentals/session/index.ts
index a185452abb..3ee1759310 100644
--- a/packages/backend/server/src/fundamentals/session/index.ts
+++ b/packages/backend/server/src/fundamentals/session/index.ts
@@ -5,7 +5,7 @@ import { SessionCache } from '../cache';
@Injectable()
export class SessionService {
private readonly prefix = 'session:';
- private readonly sessionTtl = 30 * 60 * 1000; // 30 min
+ public readonly sessionTtl = 30 * 60 * 1000; // 30 min
constructor(private readonly cache: SessionCache) {}