fix(search): correct tenant token filter quoting and ensure string return
This commit is contained in:
parent
554ff730e6
commit
7d056ffd57
1 changed files with 9 additions and 4 deletions
|
|
@ -72,16 +72,21 @@ async function configureIndex(index) {
|
||||||
export function generateTenantToken(userId, organizationIds, expiresIn = 3600) {
|
export function generateTenantToken(userId, organizationIds, expiresIn = 3600) {
|
||||||
const client = getMeilisearchClient();
|
const client = getMeilisearchClient();
|
||||||
|
|
||||||
|
// Quote string values for Meilisearch filter syntax
|
||||||
|
const orgList = (organizationIds || []).map((id) => `"${id}"`).join(', ');
|
||||||
|
const filter = `userId = "${userId}" OR organizationId IN [${orgList}]`;
|
||||||
|
|
||||||
const searchRules = {
|
const searchRules = {
|
||||||
[INDEX_NAME]: {
|
[INDEX_NAME]: { filter }
|
||||||
filter: `userId = ${userId} OR organizationId IN [${organizationIds.join(', ')}]`
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const expiresAt = new Date(Date.now() + expiresIn * 1000);
|
const expiresAt = new Date(Date.now() + expiresIn * 1000);
|
||||||
|
|
||||||
return client.generateTenantToken(searchRules, {
|
// Ensure a string is returned across client versions
|
||||||
|
const token = client.generateTenantToken(searchRules, {
|
||||||
apiKey: MEILISEARCH_MASTER_KEY,
|
apiKey: MEILISEARCH_MASTER_KEY,
|
||||||
expiresAt
|
expiresAt
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return typeof token === 'string' ? token : String(token);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue