better-auth-cloudflare
Version:
Seamlessly integrate better-auth with Cloudflare Workers, D1, Hyperdrive, KV, R2, and geolocation services.
30 lines (29 loc) • 942 B
JavaScript
/**
* Cloudflare client plugin for Better Auth
*/
export const cloudflareClient = () => {
return {
id: "cloudflare",
$InferServerPlugin: {},
getActions: $fetch => {
return {
/**
* Upload a file by sending it directly as the request body with metadata in headers.
*/
uploadFile: async (file, metadata) => {
const headers = {
"x-filename": file.name,
};
if (metadata && Object.keys(metadata).length > 0) {
headers["x-file-metadata"] = JSON.stringify(metadata);
}
return $fetch("/files/upload-raw", {
method: "POST",
headers,
body: file,
});
},
};
},
};
};