| @@ -18,8 +18,9 @@ | ||
| 18 | 18 | namespace WCPOS\WooCommercePOS\Templates; |
| 19 | 19 | |
| 20 | 20 | use WCPOS\WooCommercePOS\Logger; |
| 21 | 21 | use WCPOS\WooCommercePOS\Services\Auth as AuthService; |
| 22 | +use WCPOS\WooCommercePOS\Services\Cashier; | |
| 22 | 23 | use WP_Error; |
| 23 | 24 | use WP_User; |
| 24 | 25 | |
| 25 | 26 | /** |
| @@ -53,11 +54,19 @@ | ||
| 53 | 54 | |
| 54 | 55 | /** |
| 55 | 56 | * Allowed redirect URI schemes. |
| 56 | 57 | * |
| 58 | + * The native app registers one URL scheme per build profile so that a | |
| 59 | + * device with two variants installed (e.g. the store build and the dev | |
| 60 | + * client) returns the login to the app that started it: `wcpos` for the | |
| 61 | + * store build, `wcpos-dev` for the development client, `wcpos-adhoc` for | |
| 62 | + * ad-hoc test builds (monorepo `apps/main/app.config.ts`). `exp` is the | |
| 63 | + * Expo Go client. Matching is an exact `<scheme>://` prefix, so listing | |
| 64 | + * `wcpos-dev` does not admit `wcpos-devious`. | |
| 65 | + * | |
| 57 | 66 | * @var array |
| 58 | 67 | */ |
| 59 | - private const ALLOWED_SCHEMES = array( 'wcpos', 'exp', 'https', 'http' ); | |
| 68 | + private const ALLOWED_SCHEMES = array( 'wcpos', 'wcpos-dev', 'wcpos-adhoc', 'exp', 'https', 'http' ); | |
| 60 | 69 | |
| 61 | 70 | /** |
| 62 | 71 | * The redirect URI. |
| 63 | 72 | * |
| @@ -308,11 +317,11 @@ | ||
| 308 | 317 | return; |
| 309 | 318 | } |
| 310 | 319 | |
| 311 | 320 | // Check if user has access to POS. |
| 312 | - if ( ! user_can( $user, 'access_woocommerce_pos' ) ) { | |
| 321 | + if ( ! Cashier::instance()->can_open_pos( $user ) ) { | |
| 313 | 322 | $this->log_auth_attempt( $username, 'no_permission' ); |
| 314 | - $this->error = __( 'You do not have permission to access the POS.', 'woocommerce-pos' ); | |
| 323 | + $this->error = Cashier::instance()->missing_pos_capabilities_message( $user ); | |
| 315 | 324 | |
| 316 | 325 | return; |
| 317 | 326 | } |
| 318 | 327 | |