@8base/react-native-auth0-auth-client 中文文档教程

发布于 3年前 浏览 19 项目主页 更新于 3年前

8base react-native auth0 auth client

AuthProvider 的 8base react-native auth0 auth 客户端。

ReactNativeAuth0AuthClient

Table of Contents

ReactNativeAuth0AuthClient

创建 react-native auth0 auth 客户端的实例。

Parameters

  • workspaceId string Identifier of the 8base app workspace.
  • domain string Domain. See auth0 documentation.
  • clientId string Client id. See auth0 documentation.

Usage

...
import { AuthContext, AuthProvider, type AuthContextProps } from '@8base/auth';
import { ReactNativeAuth0AuthClient } form '@8base/react-native-auth0-auth-client';

  const authClient = new ReactNativeAuth0AuthClient({
    domain: 'domain',
    clientId: 'client-id',
    workspaceId: 'workspace-id',
  });

  ...

  const renderAuth = (auth) => {
    const authorize = async () => {
      const authData = await auth.authorize();

      await auth.setAuthState({
        token: authData.idToken,
        email: authData.email,
      });
    };

    const logout = async () => {
      await auth.purgeAuthState();
    };

    if (auth.isAuthorized) {
      return (
        <View>
          <Text>Hi ${auth.authState.email} !</Text>
          <Button title='Logout' onPress={ logout } />
        </View>
      );
    }

    return (
      <View>
        <Button title='Authorize with auth0' onPress={ authorize } />
      </View>
    );
  };

  ...

  <AuthProvider authClient={ authClient }>
    ...
      <AuthContext.Consumer>
        { renderAuth }
      </AuthContext.Consumer>
    ...  
  </AuthProvider>

8base react-native auth0 auth client

The 8base react-native auth0 auth client for the AuthProvider.

ReactNativeAuth0AuthClient

Table of Contents

ReactNativeAuth0AuthClient

Create an instance of the react-native auth0 auth client.

Parameters

  • workspaceId string Identifier of the 8base app workspace.
  • domain string Domain. See auth0 documentation.
  • clientId string Client id. See auth0 documentation.

Usage

...
import { AuthContext, AuthProvider, type AuthContextProps } from '@8base/auth';
import { ReactNativeAuth0AuthClient } form '@8base/react-native-auth0-auth-client';

  const authClient = new ReactNativeAuth0AuthClient({
    domain: 'domain',
    clientId: 'client-id',
    workspaceId: 'workspace-id',
  });

  ...

  const renderAuth = (auth) => {
    const authorize = async () => {
      const authData = await auth.authorize();

      await auth.setAuthState({
        token: authData.idToken,
        email: authData.email,
      });
    };

    const logout = async () => {
      await auth.purgeAuthState();
    };

    if (auth.isAuthorized) {
      return (
        <View>
          <Text>Hi ${auth.authState.email} !</Text>
          <Button title='Logout' onPress={ logout } />
        </View>
      );
    }

    return (
      <View>
        <Button title='Authorize with auth0' onPress={ authorize } />
      </View>
    );
  };

  ...

  <AuthProvider authClient={ authClient }>
    ...
      <AuthContext.Consumer>
        { renderAuth }
      </AuthContext.Consumer>
    ...  
  </AuthProvider>
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文