Nuxt
Nuxt
Install
1
npm i botbye-nuxt
or
1
yarn add botbye-nuxt
Client Configuration
Init BotBye! using botbye-nuxt/module
1
2
3
4
5
6
7
8
9
10
11
12
13
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"
}
}
})
Server Configuration
1. Create BotBye! init plugin in server/plugins and init with server-key
1
2
3
4
5
6
7
8
import { initBotBye } from "botbye-nuxt/server";
export default defineNitroPlugin(() => {
initBotBye({
/* Use your server-key */
serverKey: "00000000-0000-0000-0000-000000000000"
});
})
Client Usage
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<script setup
lang = "ts" >
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>
Server Usage
Add request validation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { botByeRequest } from "botbye-nuxt/server";
export default defineEventHandler(async (event) => {
// Get token from header or any place you store it.
// For example, from "x-botbye-token" header
const token = getHeader(event, "x-botbye-token");
const botByeResponse = await botByeRequest({requestEvent: event, token: token});
const isAllowed = botByeResponse.result.isAllowed;
if (!isAllowed) {
return new Error("Error!");
}
return /*some data*/
});
## Examples of BotBye API responses
Bot detected:
1
2
3
4
5
6
7
{
"reqId": "f77b2abd-c5d7-44f0-be4f-174b04876583",
"result": {
"isAllowed": false
},
"error": "Automation tool used"
}
Bot not detected:
1
2
3
4
5
6
7
{
"reqId": "f77b2abd-c5d7-44f0-be4f-174b04876583",
"result": {
"isAllowed": true
},
"error": null
}
Request banned by custom rule:
1
2
3
4
5
6
7
8
9
{
"reqId": "f77b2abd-c5d7-44f0-be4f-174b04876583",
"result": {
"isAllowed": false
},
"error": {
"message": "Banned by rule: MY_CUSTOM_RULE"
}
}
Invalid server-key:
1
2
3
4
5
6
7
{
"reqId": "f77b2abd-c5d7-44f0-be4f-174b04876583",
"result": null,
"error": {
"message": "[BotBye] Bad Request: Invalid Server Key"
}
}