The reason the phone number is used as a primary key, is that phone numbers are not unique in WordPress, whereas emails are unique (and used for account recovery.)
However, we have recently implemented new functionality that should fix this for the case where a user that has an account linked with Vipps changes his or her email address in the Vipps app or in the WordPress/WooCommerce site.
If a user logs in using Login with Vipps for the first time, an account will be created if there does not exist an account with the _verified_ email address in the Vipps app. If this account exists, the login process will log you in and link this existing account with your Vipps account.
Now earlier, this linkage only used the verified email address, but this is not the case anymore. Currently, a custom table implements a lookup from the phone number to the linked account, which means that you should be able to log onto that account no matter the email address (until you unlink it).
Now if the account exists already, but with a different email, and there is no linkage, there is a filter you can use to retrieve the correct user:
? ? ? // Allow a filter to find the user for special applications (phone number as username etc etc
? $user = apply_filters( 'login_with_vipps_authenticate_user', $user, $userinfo, $session);
However, you should then be prepared to handle the situation where if you look-up by phone number, you may get *several* accounts, because as I mentioned, phone numbers aren’t unique. Since there are many ways to handle this situation, we don’t have a default solution for it at this point.
Express Checkout currently uses a slightly different way of handling identities; so the login/user creation there is basically handled the way Woo does it, which is by using the email. Because this is verified, we can log in customers with that same email address if existing. Unfortunately we can’t link this to Vipps login accounts just yet, but we expect to be able to at some point in the future.
For Vipps Checkout, payment may be by credit card instead of the app, and of course the email address is free-form and not verified. Therefore there is currently no login logic there. However, in version 3 of checkout, which is being implemented as we speak, we can and do in fact get the correct user id when using the app to pay. For this use-case we then expect to handle the login logic correctly.
So there are basically 4 cases here:
- Change of email for linked accounts. This *should* work. If it does not, you may have found a bug and we’d be grateful if you have a minimal replicable case.
- First-time login using the phone number as lookup key. This is possible using filters, but not implemented by default because we’re not sure if there is an ideal way to handle the case of multiple accounts with the same number.
- Full integration with Vipps Express Checkout. Hopefully coming soon as Vipps migrate to new APIs.
- Full integration with Vipps Checkout. Should be possible in the nearer future.