Skip to content

Commit

Permalink
refactor: use environment variable to determine captcha manager
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhuapiaoyuan committed Nov 17, 2024
1 parent 14c32ef commit 9919dd9
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions apps/example/src/service/captcha.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CaptchaManager } from '@next-auth-oauth/wechatmp'
import { CaptchaManager, MemoryCaptchaManager } from '@next-auth-oauth/wechatmp'
import { Redis } from '@upstash/redis'

// const redis = new Redis({
Expand Down Expand Up @@ -86,13 +86,15 @@ export class RedisCaptchaService implements CaptchaManager {
}
}

export const captchaManager = new RedisCaptchaService(
new Redis({
url: process.env.KV_REST_API_URL,
token: process.env.KV_REST_API_TOKEN,
}),
{
expireTime: 60000 * 2,
length: 6,
},
)
export const captchaManager = process.env.KV_REST_API_URL
? new RedisCaptchaService(
new Redis({
url: process.env.KV_REST_API_URL,
token: process.env.KV_REST_API_TOKEN,
}),
{
expireTime: 60000 * 2,
length: 6,
},
)
: new MemoryCaptchaManager()

0 comments on commit 9919dd9

Please sign in to comment.