fix: infinity scroll, init data in base64
This commit is contained in:
@@ -2,15 +2,20 @@ import {ofetch} from "ofetch";
|
||||
|
||||
const BASE_URL = '/';
|
||||
|
||||
function encodeBase64Unicode(str) {
|
||||
return btoa(new TextEncoder().encode(str).reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
||||
}
|
||||
|
||||
export const apiFetch = ofetch.create({
|
||||
throwHttpErrors: true,
|
||||
onRequest({request, options}) {
|
||||
const data = window.Telegram?.WebApp?.initData;
|
||||
|
||||
if (data) {
|
||||
const encoded = encodeBase64Unicode(data);
|
||||
options.headers = {
|
||||
...options.headers,
|
||||
'X-Telegram-InitData': data,
|
||||
'X-Telegram-InitData': encoded,
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user