feat: use custom verify token policy (#5836)

This commit is contained in:
DarkSky
2024-02-20 09:47:27 +08:00
committed by GitHub
parent df157819dc
commit fd18732e6e
2 changed files with 19 additions and 1 deletions

View File

@@ -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,

View File

@@ -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) {}