# bitexpert/magento2-force-customer-login

> The Force Login module for Magento2 redirects a storefront visitor to the Magento2 Frontend login page, if the visitor is not logged in. It is possible to configure the whitelisted urls to add custom definitions.

`composer require bitexpert/magento2-force-customer-login`

Canonical URL: https://packagento.com/bitexpert/magento2-force-customer-login

## At a glance

- **Vendor**: bitexpert (https://packagento.com/bitexpert.md)
- **Latest version**: 5.4.0 — released 2024-05-01
- **Pricing**: Free
- **Package type**: Magento 2 module
- **Status**: active, accepting new buyers

## Installation

Packagento is licence-gated, so even free packages need a licence on a project before Composer can resolve them.

1. **Sign in or create an account** at https://packagento.com/customer/account/.

2. **Add the package to your account.** Open https://packagento.com/bitexpert/magento2-force-customer-login and complete the free checkout. A licence is minted automatically.

3. **Create or pick a project, then activate the licence on it.**
   - Projects represent the Magento installs you deploy to. Manage them at https://packagento.com/projects/.
   - Activate the new licence on the project you'll deploy this package to. Activation is what generates the Composer credentials scoped to that project.

4. **Add the project credentials to your Magento codebase.**

   Grab the project's public + private key from https://packagento.com/projects/ (open the project, then its Credentials tab), and add them to `auth.json`:

   ```json
   {
     "http-basic": {
       "packagento.com": {
         "username": "ppk_live_...",
         "password": "psk_live_..."
       }
     }
   }
   ```

   Add the Packagento Composer repository to `composer.json`:

   ```json
   {
     "repositories": [
       { "type": "composer", "url": "https://packagento.com" }
     ]
   }
   ```

5. **Install and apply.**

   ```bash
   composer require bitexpert/magento2-force-customer-login:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## What it does

The Force Login module for Magento2 redirects a storefront visitor to the Magento2 Frontend login page, if the visitor is not logged in. It is possible to configure the whitelisted urls to add custom definitions.

## README

[![Build Status](https://github.com/bitExpert/magento2-force-login/workflows/ci/badge.svg?branch=master)](https://github.com/bitExpert/magento2-force-login/actions)
[![Coverage Status](https://coveralls.io/repos/github/bitExpert/magento2-force-login/badge.svg?branch=master)](https://coveralls.io/github/bitExpert/magento2-force-login?branch=master)
[![Mastodon Follow](https://img.shields.io/mastodon/follow/109408681246972700?domain=https://rheinneckar.social)](https://rheinneckar.social/@bitexpert)

The **Force Login** Module for *Magento® 2* allows you to restrict which pages a visitor is
able to see. Visitors get redirected to the login page if the page is not marked visitable.
The **Force Login** Module for *Magento® 2* is especially useful for merchants serving only a specific
group of users, e.g. enterprise related business partners and need to ensure that only those users are
able to browse the the website or the product catalog.

### Features:
* Force your guest visitors to log in first (or register), before allowing them to visit your pages and catalog
* Administration: Manage the whitelist rules by the GUI in the administration area
* ACL: Restrict the administration of whitelist rules to certain backend user groups
* Whitelisting: Define url rules as pattern to define which pages guest visitors can visit without logging in first
* Multistore-Support: Define if whitelist rules either apply globally or for specific stores
* [Hyvä Themes](https://hyva.io) compatible

### Requirements:
* PHP 7.4 or PHP 8.1
* Magento 2.4.0 or higher

### Installation
The preferred way of installing `bitexpert/magento2-force-customer-login` is through Composer. Simply add `bitexpert/magento2-force-customer-login` 
as a dependency:

```
composer.phar require bitexpert/magento2-force-customer-login
```

Optional you can download the latest version [here](https://github.com/bitExpert/magento2-force-login/releases) and install the
decompressed code in your projects directory under *app/code/BitExpert/ForceCustomerLogin*.  

##### Composer error package bitexpert/magento2-force-customer-login exists
When you have errors after installing trough composer there is probably an issue with version numbers between Packagist and Magento repo. You can update your project composer file to fix this: 
```
{
  "repositories": [
    {
      "type": "composer",
      "url": "https://repo.magento.com/",
      "canonical": false
    }
  ]
}
```

### Post-Install

After the installment of the module source code, the module has to be enabled by the *Magento® 2* CLI.

```
bin/magento module:enable BitExpert_ForceCustomerLogin
```

### System Upgrade

After enabling the module, the *Magento® 2* system must be upgraded. 

If the system mode is set to *production*, run the *compile* command first. This is not necessary for the *developer* mode.
```
bin/magento setup:di:compile
```

To upgrade the system, the *upgrade* command must be run.
```
bin/magento setup:upgrade
```

### Clear Cache

At last, the *Magento® 2* should be cleared by running the *flush* command.
```
bin/magento cache:flush
```

Sometimes, other cache systems or services must be restarted first, e.g. Apache Webserver and PHP FPM.

## User Guide
Find the complete user guide [here](./docs/UserGuide.pdf "User Guide").

### How to use
The usage of the **Force Login** Module for *Magento® 2* is applied implicitly by redirecting visitors 
if the called URI does not match any configured whitelisted url rules.

#### Whitelisting

Whitelisting is based upon the usage of rules. The strategy selection defines how the rules are interpreted, [details are listed below](#strategies).
By default, some static rules are already listed. The following example shows, how to add a whitelist entry for the homepage (startpage).

Navigate to the **Overview Grid** and use the *Add Entry* button.

- Enter **Homepage** into the text field beside from the **Label** label.
- Enter **^/?$** into the text field beside from the **Url Rule** label.
- Select **All Stores** from the selection field beside from the **Store** label.

Use the **Save** button in the upper menu. After being redirected to the **Overview Grid**, the new 
entry should appear to the list and the systems homepage should be available for guest visitors.

### How to configure

#### Administration

The **Force Login** Module for *Magento® 2* allows you to enable or disable the module itself on the level of websites, stores and store views.

If the module is *disabled*, the whitelist ruling and the redirection are not applied. If the module is *enabled* based upon the configuration,
the whitelist rules are process, which themselves are also configurable for all enabled stores or just specific ones.

After installing and enabling **Force Login** Module for *Magento® 2* with the CLI, you must be able to navigate to 
*Stores > Configuration > Force Login*, where you are able to configure the availability of the module for each website, store and store view.

In the administration configuration, you are also able to setup the URL the redirecting is targeting to if not whitelist rule is matching.

![alt text](./resources/ui_step_00.png "Administration")

#### Navigation
Navigating through the *Magento® 2* backend menu by clicking onto **Customers** you must see a new menu 
entry **Forced Login Whitelist**. 

Enter this menu entry.

![alt text](./resources/ui_step_01.png "UI Navigation")

_(README truncated for .md surface. Full README on https://packagento.com/bitexpert/magento2-force-customer-login.)_

## Changelog

All notable changes to this project will be documented in this file, in reverse chronological order by release.

### 5.4.0

#### Added

- Nothing.

#### Deprecated

- Nothing.

#### Removed

- Nothing.

#### Fixed

- [#232](https://github.com/bitExpert/magento2-force-login/pull/232) Updating PHP version for Magento 2.4.7
- [#230](https://github.com/bitExpert/magento2-force-login/pull/230) A whitelist entry is not editable Error after trying to update the module

### 5.3.0

#### Added

- Nothing.

#### Deprecated

- Nothing.

#### Removed

- Nothing.

#### Fixed

- [#229](https://github.com/bitExpert/magento2-force-login/pull/229) Restore default whitelist all get static strategy

### 5.2.0

#### Added

- [#227](https://github.com/bitExpert/magento2-force-login/pull/227) add support for php 8.2

#### Deprecated

- Nothing.

#### Removed

- Nothing.

#### Fixed

- [#228](https://github.com/bitExpert/magento2-force-login/pull/228) Add module enabled check to plugin enabled

### 5.1.0

#### Added

- [#224](https://github.com/bitExpert/magento2-force-login/pull/224) Make module compatible with Magento 2.4.5
- [#218](https://github.com/bitExpert/magento2-force-login/pull/218) Upgrade PHPStan to version 1.7
- [#217](https://github.com/bitExpert/magento2-force-login/pull/217) Update readme, add composer error instructions

#### Deprecated

- Nothing.

#### Removed

- Nothing.

#### Fixed

- [#223](https://github.com/bitExpert/magento2-force-login/pull/223) Add db_schema_whitelist.json to fix issue

### 5.0.1

#### Added

- [#214](https://github.com/bitExpert/magento2-force-login/pull/214) Migrate to db_schema.xml
- [#213](https://github.com/bitExpert/magento2-force-login/pull/213) Extend CI pipeline with more Magento versions

#### Deprecated

- Nothing.

#### Removed

- Nothing.

#### Fixed

- [#215](https://github.com/bitExpert/magento2-force-login/pull/215) Update default routes

### 5.0.0

#### Added

- [#211](https://github.com/bitExpert/magento2-force-login/pull/211) M2.4.4 compability
- [#197](https://github.com/bitExpert/magento2-force-login/pull/197) Allow the store column to be sorted in the grid view
- [#188](https://github.com/bitExpert/magento2-force-login/pull/188) Paypal Ipn

#### Deprecated

- [#202](https://github.com/bitExpert/magento2-force-login/pull/202) Only support M2.4.x

#### Removed

- Nothing.

#### Fixed

- [#212](https://github.com/bitExpert/magento2-force-login/pull/212) Allow Magento admin to log in as customer
- [#209](https://github.com/bitExpert/magento2-force-login/pull/209) Fix bug for wrong redirect on customer login and account confirmation
- [#206](https://github.com/bitExpert/magento2-force-login/pull/206) Homepage Redirect After Login Leads To incorrect url
- [#198](https://github.com/bitExpert/magento2-force-login/pull/198) Fix undefined method call

### 4.1.0

#### Added

- [#191](https://github.com/bitExpert/magento2-force-login/pull/191) Added support for Magento 2.4
- [#187](https://github.com/bitExpert/magento2-force-login/pull/187) Skip dynamic asset request
- [#186](https://github.com/bitExpert/magento2-force-login/pull/186) Fixed registration redirect

#### Deprecated

- Nothing.

#### Removed

- Nothing.

#### Fixed

- [#192](https://github.com/bitExpert/magento2-force-login/issues/192) force login in store redirects to default login
- [#180](https://github.com/bitExpert/magento2-force-login/issues/180) Customers get whoops.... after registering
- [#179](https://github.com/bitExpert/magento2-force-login/issues/179) Improve menu placement: fix compatibility with B2B
- [#161](https://github.com/bitExpert/magento2-force-login/issues/161) After login in shows css page

### 4.0.1

#### Added

- Nothing.

#### Deprecated

- Nothing.

#### Removed

- Nothing.

#### Fixed

- [#167](https://github.com/bitExpert/magento2-force-login/pull/167) Password Reset not working

### 4.0.0

#### Added

_(Changelog truncated for .md surface. Full history on https://packagento.com/bitexpert/magento2-force-customer-login.)_

## Recent Versions

| Version | Released |
|---|---|
| 5.4.0 | 2024-05-01 |
| 5.3.0 | 2023-11-12 |
| 5.2.0 | 2023-10-29 |
| 5.1.0 | 2022-10-31 |
| 5.0.1 | 2022-05-14 |
| 5.0.0 | 2022-05-13 |
| 4.1.0 | 2020-10-19 |
| 4.0.2 | 2019-12-27 |
| 4.0.1 | 2019-12-16 |
| 4.0.0 | 2019-11-02 |

Showing 10 of 46 versions. Full release history on https://packagento.com/bitexpert/magento2-force-customer-login.

## Dependencies

### Require

| Package | Constraint |
|---|---|
| magento/framework | ^103.0.4 |
| magento/module-backend | ^102.0.4 |
| magento/module-customer | ^103.0.4 |
| magento/module-store | ^101.1.4 |
| magento/module-ui | ^101.2.4 |
| php | ~8.1.0\|~8.2.0\|~8.3.0 |

### Require (dev)

| Package | Constraint |
|---|---|
| bitexpert/phpstan-magento | ^0.30.0 |
| captainhook/captainhook | ^5.16.4 |
| captainhook/plugin-composer | ^5.3.3 |
| magento/magento-coding-standard | ^31 |
| php-coveralls/php-coveralls | ^2.7 |
| phpstan/extension-installer | ^1.3.1 |
| phpstan/phpstan | ^1.10.33 |
| phpunit/phpunit | ^9.5.2 |

## Quality

Latest release (5.4.0) fails the Packagento QA pipeline. Verdicts below are per-cell (Magento line × PHP version) for the matrixed tools, and run-once for the static / security tiers.


### Compatibility

Each Magento line is installed on its supported PHP versions, then the module is built (DI compile + static-content deploy). Cells show passed / failed / untested; staircase gaps render as `–`.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | Pass | Pass | – | – |
| 2.4.8 | – | Pass | not tested | – |
| 2.4.9 | – | – | not tested | not tested |


### Code Quality

Advisory checks against the module's source. Never affect the Compatibility verdict — a phpcs finding can't make a module incompatible.

#### Static Analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| PHPCS | Fail | 454 | 29 errors, 425 warnings (ruleset: Magento2) — 256 auto-fixable with phpcbf |
| PHPMD | Warning | 45 | 45 rule violations (ErrorControlOperator:18, MissingImport:14, ExcessiveMethodLength:6, UnusedLocalVariable:2, CyclomaticComplexity:1) |
| Cpd | Warning | 12 | 12 duplicated chunks spanning 560 total lines (min-lines=5, min-tokens=70) |
| Composer validate | Info | 1 | valid; 1 advisory note (composer validate --strict) |

#### PHPStan

Type-checks the module against a real Magento install. Re-runs per Magento + PHP version because resolvable symbols differ between releases.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | Unknown | 22 | – | – |
| 2.4.8 | – | 22 | N/A | – |
| 2.4.9 | – | – | N/A | N/A |


### Tests

Unit and integration suites run per Magento + PHP cell. Test failures speak to the module's behaviour, not its compatibility with a line, so they're reported here separately.

#### Unit Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | Pass | Pass | – | – |
| 2.4.8 | – | 12 | not tested | – |
| 2.4.9 | – | – | N/A | not tested |

#### Integration Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |


### Security

Dependency-advisory audit (composer audit) plus a source malware scan. A malware detection fails the version outright.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| Composer audit | Pass | 0 |  |
| Malware scan | Pass | 0 |  |

## Licence and pricing

Free. A licence is still minted on checkout and bound to your project for Composer access — no payment step.

Refundable within 14 days of first purchase via https://packagento.com/account/refunds/.

## Install via Claude Code or any MCP client

The Packagento MCP server can run the licence + project + Composer steps above in one tool call:

```
purchase_and_install_packages(
  composer_names=["bitexpert/magento2-force-customer-login"],
  project_id="proj_xxx"
)
```

This handles cart, checkout, licence minting, project activation, and writes auth.json credentials. Connect a client with `claude mcp add packagento https://mcp.packagento.com`. Full setup at https://packagento.com/docs/mcp-setup.

## Vendor

bitexpert is a Magento 2 vendor on Packagento. See https://packagento.com/bitexpert.md for their full catalogue.

