Skip to content

Commit

Permalink
check whether token exists before making query
Browse files Browse the repository at this point in the history
  • Loading branch information
hannessolo committed Jul 2, 2024
1 parent 39f8c29 commit e57e93c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scripts/wishlist/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ mutation(
`;

export async function getWishlists() {
const token = getSignInToken(redirectToSignin);
const token = getSignInToken();
if (!token) {
redirectToSignin();
}

const wishlists = await performMonolithGraphQLQuery(
getWishlistsQuery,
Expand All @@ -75,8 +78,12 @@ export async function getWishlists() {
* @returns {Promise<void>}
*/
export async function addToWishlist(product, wishlistId) {
const token = getSignInToken();
if (!token) {
redirectToSignin();
}

const toWishlist = wishlistId ?? (await getWishlists())[0].id;
const token = getSignInToken(redirectToSignin);

const response = await performMonolithGraphQLQuery(
addProductToWishlistMutation,
Expand Down

0 comments on commit e57e93c

Please sign in to comment.