1.1.7 • Published 1 year ago
@foundbyte/auth v1.1.7
auth
TODO: captcha auth library by Foundbyte
install
yarn add @foundbyte/auth
// or
npm install @foundbyte/auth
Usage
import React, { useRef, useState } from 'react';
import { Captcha, useCaptcha } from '@foundbyte/auth';
import { print } from '@foundbyte/util';
export default () => {
const ref = useRef<any>();
const [path, setPath] = useState<string>('https://api.ejiexi.com/system/cgi');
const [run] = useCaptcha({
path: path,
type: 'auto',
});
const onClick = () => {
ref.current?.verify();
};
return (
<>
<Captcha
onSuccess={data => print.success(data)}
path={path}
type="auto"
ref={ref}
>
<button onClick={onClick} className='demo-btn'>
点击
</button>
<button className='demo-btn' onClick={async () => {
try {
if (run) {
const data = await run();
print.success(data);
}
} catch (e) {
print.error(e);
}
}}>
hook
</button>
</Captcha>
</>
);
};