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"],
botbyeModule: {
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
Blocked (bot detected):
1
2
3
4
5
6
7
8
{
"request_id": "f77b2abd-c5d7-44f0-be4f-174b04876583",
"decision": "BLOCK",
"risk_score": 0.95,
"scores": { "bot": 0.95 },
"signals": ["AutomationTool"],
"config": { "bypass_bot_validation": false }
}
Allowed:
1
2
3
4
5
6
7
8
{
"request_id": "f77b2abd-c5d7-44f0-be4f-174b04876583",
"decision": "ALLOW",
"risk_score": 0.05,
"scores": { "bot": 0.05, "ato": 0.02 },
"signals": [],
"config": { "bypass_bot_validation": false }
}
Challenge:
1
2
3
4
5
6
7
8
9
{
"request_id": "f77b2abd-c5d7-44f0-be4f-174b04876583",
"decision": "CHALLENGE",
"risk_score": 0.65,
"scores": { "bot": 0.65 },
"signals": ["SuspiciousFingerprint"],
"challenge": { "type": "captcha", "token": "..." },
"config": { "bypass_bot_validation": false }
}
Invalid server-key:
1
2
3
4
5
{
"decision": "ALLOW",
"config": { "bypass_bot_validation": true },
"error": { "message": "[BotBye] Bad Request: Invalid Server Key" }
}