donny-test-nuxt-plugin
v1.0.18
Published
```bash npm i botbye-nustjs ```
Readme
NuxtJS BotBye!
Install
npm i botbye-nustjsyarn add botbye-nuxtjsUsage
Server
- Init BotBye! with
server-key
import {initBotByeServerKey} from "botbye-nustjs/server";
initBotByeServerKey({
/* Use your server-key */
serverKey: "00000000-0000-0000-0000-000000000000"
})
- Add request validation
import {botByeRequest, initBotByeServerKey} from "protection-nuxt/server";
export default defineEventHandler(async (event) => {
const reqHeader = getHeaders(requestEvent);
const token = getToken(reqHeader);
initBotByeServerKey({serverKey: "00000000-0000-0000-0000-000000000000"});
const botByeResponse = await botByeRequest({requestEvent: event, token: token});
const isAllowed = botByeResponse.result.isAllowed;
if (!isAllowed) {
return new Error("Error!");
}
return /*some data*/
});
Client
- Init BotBye! using protection-nuxt/plugin
export default defineNuxtConfig({
/* some config*/
plugins: ["protection-nuxt/plugin"],
runtimeConfig: {
public: {
clientKey: "00000000-0000-0000-0000-000000000000"
}
}
})- To run challenge and generate BotBye! token call runChallenge. Send this token in any convenient way to the server. For example in ["x-botbye-token"] header:
<script setup
lang = "ts" >
import {runChallenge} from "botbye-nustjs";
async function handleSubmit() {
const token = await runChallenge();
const res = await $fetch("/api/login", {
method: "GET",
headers: {
["x-botbye-token"]: token
}
})
}
/*or hook*/
try {
const token = await runChallenge();
const {data: res, error: fetchError} = useFetch(
'/api/login',
{
method: 'post',
headers: {
'x-botbye-token': token
}
}
)
} catch (e) {
throw e;
}
</script>