Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move favorite-toggling validation to the server #1

Open
karashiiro opened this issue Aug 24, 2022 · 0 comments
Open

Move favorite-toggling validation to the server #1

karashiiro opened this issue Aug 24, 2022 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers priority: 2 Next highest priority

Comments

@karashiiro
Copy link
Collaborator

Code:

const toggleFavorite = async () => {
if (user == null) {
return;
}
const backend = connectBackend();
// This should be done on the server later, it's just simpler to do this here for now
try {
const favorites = await backend.app.records.getList('profile_preset_favorites', 1, 1, {
filter: `profile='${user.profile?.id}'`
});
if (favorites.totalItems === 0) {
try {
await backend.app.records.create('profile_preset_favorites', {
profile: user.profile?.id,
preset: data.preset.id
});
isFavorite = true;
} catch (err) {
console.error(err);
}
} else {
try {
await backend.app.records.delete('profile_preset_favorites', favorites.items[0].id);
isFavorite = false;
} catch (err) {
console.error(err);
}
}
} catch (err) {
console.error(err);
}
};

Allowing this validation to be done on the client could allow a modified client to add a preset to the user's favorites multiple times.

@karashiiro karashiiro added bug Something isn't working good first issue Good for newcomers priority: 2 Next highest priority labels Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers priority: 2 Next highest priority
Projects
None yet
Development

No branches or pull requests

1 participant