Skip to content

Troubleshooting

Common issues and their solutions when working with NextPresser.

Connection Issues

Cannot Connect to WordPress

Problem: NextPresser cannot connect to your WordPress GraphQL endpoint.

Solutions: 1. Verify NEXT_PUBLIC_WORDPRESS_URL is correct 2. Check that WPGraphQL plugin is installed and activated 3. Verify CORS settings in WordPress 4. Check network connectivity

GraphQL Endpoint Not Found

Problem: Getting 404 errors when accessing /graphql.

Solutions: 1. Ensure WPGraphQL plugin is activated 2. Check permalink settings in WordPress 3. Verify the endpoint URL in your configuration

Authentication Issues

JWT Token Expired

Problem: Authentication tokens are expiring too quickly.

Solutions: 1. Increase token expiration time 2. Implement token refresh logic 3. Check token generation settings

Performance Issues

Slow Page Loads

Problem: Pages are loading slowly.

Solutions: 1. Enable ISR (Incremental Static Regeneration) 2. Implement proper caching 3. Optimize GraphQL queries 4. Use image optimization

Build Errors

TypeScript Errors

Problem: TypeScript compilation errors.

Solutions: 1. Run npm run type-check 2. Update type definitions 3. Check for missing dependencies

Logout Issues

Logout Functionality Not Working

Problem: The logout button is not fully working - users remain logged in after clicking logout.

Root Causes Identified:

  1. Missing Cookie Clearing: WordPress uses cookie-based authentication, and the logout function wasn't properly clearing all WordPress/WooCommerce session cookies
  2. WooCommerce Session Not Cleared: The WooCommerce session stored in localStorage (woo-session) wasn't being cleared
  3. Incomplete Cleanup Order: The cleanup steps weren't in the optimal order, and some steps might not complete before redirect

Fixes Applied:

  • Added clearAllCookies() function that:
  • Identifies all cookies in the browser
  • Clears WordPress-specific cookies (e.g., wordpress_logged_in_*, wordpress_*, wp_*)
  • Clears WooCommerce cookies (e.g., woocommerce_session_*, woocommerce_cart_*)
  • Attempts to clear cookies with multiple path/domain combinations to ensure they're removed
  • Handles cookies with different security flags (secure, SameSite)

2. Proper Cleanup Sequence

The logout now follows this sequence: 1. Call logout mutation - Clears server-side session (if available) 2. Clear WooCommerce session - Removes woo-session and woocommerce-cart from localStorage 3. Clear all cookies - Removes all WordPress/WooCommerce cookies 4. Clear Apollo cache - Clears GraphQL cache and resets store 5. Clear all storage - Removes remaining localStorage and sessionStorage 6. Redirect - Redirects to home page with timestamp to prevent caching

3. Enhanced Error Handling

  • Even if the logout mutation fails, all client-side cleanup still happens
  • Comprehensive error handling ensures redirect always occurs
  • Added delays to ensure cleanup completes before redirect

Backend Requirements:

  1. Logout Mutation Must Be Enabled
  2. The logout mutation must be available in your GraphQL schema
  3. This is typically provided by:

    • wp-graphql-cors plugin (recommended) - provides enhanced logout with cookie clearing
    • wp-graphql core plugin - provides basic logout mutation
  4. Enable Logout Mutation in wp-graphql-cors

  5. Go to WordPress Admin → GraphQL → Settings → CORS Settings
  6. Enable "Add logout mutation for destroying user session"
  7. Ensure "Send site credentials" is also enabled

  8. Cookie Settings

  9. Ensure cookies are set with proper domain/path
  10. If using cross-domain setup, ensure SameSite and Secure flags are configured correctly

Testing Checklist:

After deploying the fix, test the following:

  • Click "Log out" button
  • User is redirected to home page
  • User cannot access /account pages (should redirect to login)
  • Browser DevTools → Application → Cookies shows no WordPress/WooCommerce cookies
  • Browser DevTools → Application → Local Storage shows no woo-session or woocommerce-cart
  • Browser DevTools → Application → Session Storage is empty
  • After logout, attempting to access account pages redirects to login
  • No errors in browser console during logout
  • User can log in again after logout

Troubleshooting Logout Issues:

  1. Check if logout mutation exists:
  2. Open browser DevTools → Network tab
  3. Click logout button
  4. Look for GraphQL request to /graphql
  5. Check if mutation is logout and if it returns success
  6. If mutation doesn't exist, enable it in wp-graphql-cors settings

  7. Check cookies:

  8. Open DevTools → Application → Cookies
  9. Before logout, note all WordPress/WooCommerce cookies
  10. After logout, verify they're all gone
  11. If cookies remain, check cookie domain/path settings

  12. Check console logs:

  13. Open browser console
  14. Click logout
  15. Look for [Auth] log messages
  16. Should see: "Starting logout process", "Logout mutation successful", "Cookies cleared", etc.
  17. If errors appear, note them for debugging

  18. Verify Apollo cache is cleared:

  19. After logout, try accessing account page
  20. Should redirect to login immediately
  21. If it shows cached data, Apollo cache might not be clearing properly

Common Issues:

Issue: User can still access account pages after logout - Cause: Cookies not being cleared properly - Solution: Check cookie domain/path, ensure clearAllCookies() is working

Issue: Logout mutation fails - Cause: Mutation not enabled in wp-graphql-cors - Solution: Enable logout mutation in WordPress admin settings

Issue: User redirected but still logged in - Cause: Server-side session not cleared - Solution: Ensure logout mutation is working, check WordPress session handling

Getting Help

If you're still experiencing issues: