Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why it is not work in nextjs@13? #59

Open
xm-c opened this issue Sep 19, 2023 · 1 comment
Open

why it is not work in nextjs@13? #59

xm-c opened this issue Sep 19, 2023 · 1 comment

Comments

@xm-c
Copy link

xm-c commented Sep 19, 2023

Do you want to request a feature or report a bug?

If this is a feature request, what is motivation for changing the behavior?

If it is a bug, which version of svg-captcha are you using?

What is the current behavior?

What is the expected behavior?

Step to reproduce the bug or other relevant information

@kmvan
Copy link

kmvan commented Oct 2, 2023

Not works in next13.
So I make a service for fetch captcha.

import { StatusCodes } from 'http-status-codes'
export interface SvgCaptchaCreateProps {
  data: string
  text: string
}
export interface SvgCaptchaOption {
  width?: number
  height?: number
  fontSize?: number
  mathMin?: number
  mathMax?: number
  noise?: number
  color?: boolean
  background?: string
}
export class SvgCaptcha {
  private static REMOTE_URL = 'https://svg-captcha.inn-studio.com'
  public static create = async ({
    width = 200,
    height = 50,
    fontSize = 50,
    mathMin = 10,
    mathMax = 99,
    noise = 5,
    color = true,
    background = '',
  }: SvgCaptchaOption): Promise<SvgCaptchaCreateProps | null> => {
    const params = new URLSearchParams({
      width: String(width),
      height: String(height),
      fontSize: String(fontSize),
      mathMin: String(mathMin),
      mathMax: String(mathMax),
      noise: String(noise),
      color: color ? '1' : '0',
      background,
    }).toString()
    try {
      const res = await fetch(`${this.REMOTE_URL}?${params}`, {
        cache: 'no-cache',
      })
      if (res.status !== StatusCodes.OK) {
        return null
      }
      const data = await res.json()
      if (data?.svg && data?.text) {
        return {
          data: data.svg,
          text: data.text,
        }
      }
      return null
    } catch (err) {
      console.log(err)
      return null
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants