# Supervised Login
source: https://developer.mastercard.com/open-finance-europe/documentation/unlicensed/aiia-data/connect/supervised/index.md

To perform a supervised login, end-users are required to take action. That means end-users have to login to their bank accounts again if you want to keep using those accounts.

#### When will a supervised login be needed? {#when-will-a-supervised-login-be-needed}

There are a couple of scenarios where end-users are required to perform a supervised login:

* Supervised logins are required for first time end-users connecting to our service and logging in to their bank.
* After 90 days of last login as stated in PSD2 legislation.
* If the bank provider does not support unattended login *(no user action required)*

#### How will you be notified? {#how-will-you-be-notified}

You will be notified by webhooks when an end-user needs to do a supervised login, specifically the [connectionupdaterequiredwebhook](https://developer.mastercard.com/open-finance-europe/documentation/unlicensed/aiia-data/event-notifications/event-types/index.md) webhook.

When you receive this, you will need perform an 'update' on the user's accounts to initiate the supervised login. You can see how to do this in the [Data synchronization](https://developer.mastercard.com/open-finance-europe/documentation/unlicensed/aiia-data/data-sync/index.md) section. You will also be notified when you call a manual sync, which is again explained in [Data synchronization](https://developer.mastercard.com/open-finance-europe/documentation/unlicensed/aiia-data/data-sync/index.md).

### Handling changes {#handling-changes}

It is important that you make sure all data is correct and complete when you update. Therefore, you must make sure there are no duplicates or missing transactions.

To do this, we recommend that you fetch data at least seven days prior to the latest transaction. You must compare the new transactions with the transactions you already have, as providers do change and/or remove transactions in their end. If some transactions from a previous update have been removed in the new list of transactions, you should also remove them in your end.

#### Transaction states {#transaction-states}

A transaction can have one of the following states:

* `Booked` -- A transaction that has been fully processed by the bank
* `Reserved` -- A transaction that reserves an amount of currency
* `Scheduled` -- A transaction that will be processed at a specified date

If you use transactions that are `Reserved` or `Scheduled`, be aware that these transactions will change when the transaction is booked.

You may have an instance where you have two transaction lists with data for the same period of time. Follow these steps to get a consistent data set in your end:

* If a transaction exists in both the new and the existing list, update the existing one with the newer data
* If a transaction in the new list is not in the existing list, create it
* If a transaction in the existing list is not in the new list, delete it

**Important**   
When a transaction changes state, it will most likely get a new `id`.

##### Example {#example}

For example, a reserved transaction is removed and a new booked transaction is created with a different ID:

You remove the reserved transaction because you can no longer see its ID in the list of transactions.

##### Create or merge an existing transaction {#create-or-merge-an-existing-transaction}

When you synchronize and get new transactions, you should check for duplicates by comparing the `ids` of the new transactions with the transactions you already have.

```js
// List with new transactions from a given date until now
let newTransactionList = [...]

// List with all existing transactions for the same timespan
let oldTransactionList = [...]

for (var oldTransaction in oldTransactionList) {
  for (var newTransaction in newTransactionList) {
    if (oldTransaction.id === newTransaction.id) {
      update(oldTransaction, newTransaction)) 
    } else {
      create(newTransaction)
    }
  }
}
```

The list with new transactions is obtained by following the [Transactions](https://developer.mastercard.com/open-finance-europe/documentation/unlicensed/aiia-data/transactions/index.md) guide.

##### Remove deleted transactions {#remove-deleted-transactions}

```js
// List with new transactions from a given date until now
let newTransactionList = [...]

// List with all existing transactions for the same timespan
let oldTransactionList = [...]

for (var oldTransaction in oldTransactionList) {
  // compare transaction ids
  if (!newTransactionList.includes(oldTransaction)) {
    remove(oldTransaction) 
  }
}
```

The list with new transactions is obtained by following the [Transactions](https://developer.mastercard.com/open-finance-europe/documentation/unlicensed/aiia-data/transactions/index.md) guide.
Note: Some providers might return fewer transactions than requested. The timespan chosen for the duplication handling must not start before the last transaction received from the provider.
