You might choose to allow members to log in to your site or app with an external provider, using a custom login interface that syncs with Wix’s authentication.
Notes:
Complete the following steps to log a visitor into your site using an external authentication provider:
Once the member is logged in, you can redirect them to your home page.
Before getting started, make sure you have the following:
Once you have the member’s email addresses, you can check if any of them are associated with a Wix member ID using the Members API.
// ...
const { items } = await wixAdminClient.members
.queryMembers()
.eq("loginEmail", email)
.find();
}
Note that creating members without explicit registration is an admin function. Make sure to use a WixClient with an API key that has permission to create members.
Now that you have the Wix member ID, request access and refresh tokens for the member with the getMemberTokensForExternalLogin()
function.
// ...
const memberTokens =
await wixClient.auth.getMemberTokensForExternalLogin(
member._id,
<YOUR_API_KEY>
);
Note that getting access and refresh tokens is an admin function. Make sure to use the WixClient with your OAuth app that created this visitor, along with an API key that has permission to create member access tokens, to save the visitor’s activity from before they logged in.
Now all that’s left is to store the tokens for later.