npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wix-login-react-native

v1.0.8

Published

plug & play component to handle login flow for Wix headless projects in React Native

Downloads

30

Readme

wix-login-react-native

This is a React Native component that encapsulates Wix's "Managed Login" flow, allowing users to integrate it seamlessly into their app. By using the <WixLogin /> component at the root of your app, you get a login modal that you can open from anywhere in your app, and calls a callback when the user is fully logged in.

For more information about Wix's Managed Login Flow, head over to the Wix Headless documentation.

Installation

Ensure that your React Native project has the following dependencies installed:

  1. react and react-native
  2. @wix/sdk (documentation)
  3. expo-crypto (documentation)
  4. expo-linking (documentation)
  5. react-native-webview (documentation)

Note: These dependencies need to be installed and linked only once in your React Native project.

Then, install this package using the following command:

npm install wix-login-react-native
# or
yarn add wix-login-react-native

Usage

First, add the <WixLogin /> component to the root of your application. Provide the component with two props:

  1. A Wix Client created using createClient(...) and the OAuthStrategy auth option.
  2. A callback function that accepts the user tokens (credentials) once the user is logged in.
import { WixLogin } from 'wix-login-react-native';
import { createClient, OAuthStrategy } from '@wix/sdk';

const client = createClient({ auth: OAuthStrategy({ clientId: '<YOUR_CLIENT_ID>' }) });

const App = () => (
  <WixLogin
    client={client}
    onLoginComplete={tokens => client.auth.setTokens(tokens)}
  />
);

export default App;

Then, from anywhere in your app, import the useWixLogin hook. When you want to prompt the user to login, just run:

import { useWixLogin } from 'wix-login-react-native';

const SomeComponent = () => {
  const wixLogin = useWixLogin();
  
  const handleLogin = () => {
    wixLogin.openLoginModal();
  };

  return (
    <Button title="Login" onPress={handleLogin} />
  );
};

Authorizing your app with Wix

The first time you open the login modal, it may throw an error because you need to configure Wix to trust your app:

In order to make Wix trust your app, go to https://manage.wix.com and choose your Headless project.

From there, go to Settings > Headless Settings: Settings Page

Choose your OAuth App: Headless Settings & OAuth Apps list

And under "Allowed authorization redirect URIs", add the URL provided to you from the error message: Allowed URIs

⚠️ Important: If you’re using Expo Go, the trusted “callback URL” will change once you build your own binary, so make sure to register the production version of your callback URL before you release your app.

Additional Features

Enabling User to Cancel Login

To provide users the option to cancel the login process, you can utilize the allowUserToCancelLogin prop:

<WixLogin
    client={/* ... */}
    onLoginComplete={/* ... */}
    allowUserToCancelLogin
  />

Furthermore, if you need to handle scenarios where the user cancels the login, you can supply a callback function to the onLoginCanceled prop:

<WixLogin
    client={/* ... */}
    onLoginComplete={/* ... */}
    allowUserToCancelLogin
    onLoginCanceled={() => { /* do something */ }}
  />