botbye-nuxt
v0.2.0
Published
## Install
Readme
Nuxt BotBye!
Install
npm i botbye-nuxtyarn add botbye-nuxtUsage
Server
- Init BotBye! with
server-key
import {initBotBye} from "botbye-nuxt/server";
initBotBye({
/* Use your server-key */
serverKey: "00000000-0000-0000-0000-000000000000"
})
- Add request validation
import {botByeRequest, initBotBye} from "botbye-nuxt/server";
export default defineEventHandler(async (event) => {
const reqHeader = getHeaders(requestEvent);
const token = getToken(reqHeader);
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 botbye-nuxt/module
export default defineNuxtConfig({
/* some config*/
modules: ["botbye-nuxt/module"],
'botbye-module': {
inject: true
},
runtimeConfig: {
public: {
/* Use your client-key */
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>
import {runChallenge} from "botbye-nuxt";
async function handleSubmit() {
const token = await runChallenge();
const res = await $fetch("/api/login", {
method: "GET",
headers: {
["x-botbye-token"]: token
}
})
}
</script>