How to Redirect User form Page to Page Based on Badges?

You can achieve this by using Wix Code and the wix-users and wix-location APIs as you mentioned. Here’s a code snippet to help you redirect users based on their badges:

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';

$w.onReady(function () {
    wixUsers.currentUser
        .get()
        .then((user) => {
            // Check if the user is an Admin (replace 'Admin' with your badge name)
            if (user && user.loggedIn && user.badges.includes('Admin')) {
                // Redirect to the specific URL for Admins
                wixLocation.to('/admin-page-url'); // Replace with the URL you want to redirect Admins to
            } else {
                // Redirect to a different URL for non-Admins
                wixLocation.to('/regular-page-url'); // Replace with the URL you want to redirect non-Admins to
            }
        })
        .catch((error) => {
            console.error('Error:', error);
        });
});

Make sure to replace 'Admin', '/admin-page-url', and '/regular-page-url' with the actual badge name and the URLs you want to use for redirection.

This code will check if the user is logged in and has the ‘Admin’ badge. If they do, it will redirect them to the Admin URL; otherwise, it will redirect them to the regular URL. Hope this helps.

1 Like