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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-ali-auth-modern

v0.2.2

Published

Aliyun One-Pass Login (Mobile Number Auth) for React Native. Supports TurboModule, RN 0.81+, and Expo 54+.

Downloads

273

Readme

react-native-ali-auth-modern

English

阿里云号码认证(一键登录)React Native 模块,基于 TurboModule 架构,支持 React Native 0.81+、Expo 54+。

安装

npm install react-native-ali-auth-modern
# 或
yarn add react-native-ali-auth-modern

iOS

cd ios && pod install

Android

无需额外配置,自动链接。

最佳实践

import {
  init,
  login,
  quitLoginPage,
  checkEnvAvailable,
  accelerateLoginPage,
  AliAuthErrorCode,
  AliAuthType,
} from 'react-native-ali-auth-modern';

// App 启动时初始化(只需调用一次)
await init('你的阿里云秘钥');

// 检查环境是否支持一键登录
await checkEnvAvailable(AliAuthType.LOGIN);

// 预热授权页(加速后续 login 弹起速度)
await accelerateLoginPage(3);

// 用户点击登录
try {
  const token = await login({
    mainColor: '#007AFF',
    loginBtnText: '本机号码一键登录',
    privacyName: '隐私协议',
    privacyUrl: 'https://example.com/privacy',
    privacyAlertIsNeedShow: true,
    privacyAlertBtnContent: '同意并继续',
  });

  // 拿 token 去后端换手机号
  const { phone, jwt } = await api.verifyPhoneToken(token);

  // 关闭授权页 → 跳转主页
  quitLoginPage();
  navigation.replace('Home');
} catch (e: any) {
  quitLoginPage();
  if (e.code === AliAuthErrorCode.USER_CANCEL) {
    // 用户取消,静默处理
  } else {
    Alert.alert('登录失败', e.message);
  }
}

API

init(code)

初始化 SDK,App 生命周期内调用一次。

| 参数 | 类型 | 说明 | | ---- | -------- | --------------------------- | | code | string | 阿里云控制台获取的 App 秘钥 |

返回 Promise<boolean>

login(config)

拉起授权页并获取登录 Token。

返回 Promise<string> — 成功返回 Token 字符串

quitLoginPage()

关闭授权页。由 JS 层主动调用,控制关闭时机。

checkEnvAvailable(type)

检查当前环境是否支持一键登录或号码校验。

| 参数 | 类型 | 说明 | | ---- | -------- | ----------------------------------------------------------------------------------- | | type | number | 1 = 本机号码校验,2 = 一键登录。可用 AliAuthType.VERIFY / AliAuthType.LOGIN |

返回 Promise<boolean>

accelerateLoginPage(timeout)

预热授权页,提前调用可让 login() 秒弹授权页。

| 参数 | 类型 | 默认值 | 说明 | | ------- | -------- | ------ | -------------- | | timeout | number | 3 | 超时时间(秒) |

返回 Promise<boolean>

accelerateVerify(timeout)

预热本机号码校验。

| 参数 | 类型 | 默认值 | 说明 | | ------- | -------- | ------ | -------------- | | timeout | number | 3 | 超时时间(秒) |

返回 Promise<boolean>

getVerifyToken(timeout)

获取本机号码校验 Token(不弹 UI,直接校验当前手机号)。

| 参数 | 类型 | 默认值 | 说明 | | ------- | -------- | ------ | -------------- | | timeout | number | 3 | 超时时间(秒) |

返回 Promise<string>

getVersion()

获取 SDK 版本号。

返回 Promise<string>

getCurrentCarrierName()

获取当前运营商名称。仅 Android 有效,iOS 返回空字符串。

返回 Promise<string>

hideLoginLoading()

手动隐藏登录按钮的 loading 动画。

setCheckboxIsChecked(checked)

设置授权页协议 checkbox 的选中状态。

| 参数 | 类型 | 说明 | | ------- | --------- | -------- | | checked | boolean | 是否选中 |

queryCheckBoxIsChecked()

查询协议 checkbox 是否勾选。

返回 Promise<boolean>

closePrivacyAlertView()

关闭二次授权确认弹窗。

AliAuthUIConfig 参数

login() 方法接收的 UI 配置对象,所有参数均为可选。

导航栏

| 参数 | 类型 | 说明 | | --------------- | --------- | --------------------- | | navColor | string | 导航栏背景颜色(hex) | | navTitle | string | 导航栏标题文字 | | navTitleColor | string | 导航栏标题颜色(hex) | | navTitleSize | number | 导航栏标题字号 | | navIsHidden | boolean | 是否隐藏导航栏 | | hideNavBackItem | boolean | 是否隐藏返回按钮 |

Logo

| 参数 | 类型 | 说明 | | ------------ | --------- | ---------------------------------------------------------------------- | | logoIsHidden | boolean | 是否隐藏 Logo | | logoImage | string | Logo 图片名称(需打包在原生工程中,如 Android drawable 或 iOS Assets) | | logoWidth | number | Logo 宽度 | | logoHeight | number | Logo 高度 |

号码

| 参数 | 类型 | 说明 | | ----------- | -------- | --------------------- | | numberColor | string | 手机号掩码颜色(hex) | | numberSize | number | 手机号字号 |

Slogan

| 参数 | 类型 | 说明 | | --------------- | --------- | ------------------ | | sloganText | string | slogan 文案 | | sloganIsHidden | boolean | 是否隐藏 slogan | | sloganTextColor | string | slogan 颜色(hex) |

登录按钮

| 参数 | 类型 | 说明 | | ----------------- | -------- | ----------------------- | | mainColor | string | 登录按钮背景色(hex) | | loginBtnText | string | 登录按钮文案 | | loginBtnTextColor | string | 登录按钮文字颜色(hex) | | loginBtnTextSize | number | 登录按钮文字大小 |

切换按钮

| 参数 | 类型 | 说明 | | ----------------- | --------- | ----------------------- | | changeBtnTitle | string | "切换其他登录方式" 文案 | | changeBtnIsHidden | boolean | 是否隐藏切换按钮 |

协议和 CheckBox

| 参数 | 类型 | 说明 | | ----------------- | --------- | ------------------------------------ | | privacyName | string | 协议1名称 | | privacyUrl | string | 协议1链接 | | privacyTwoName | string | 协议2名称 | | privacyTwoUrl | string | 协议2链接 | | privacyThreeName | string | 协议3名称 | | privacyThreeUrl | string | 协议3链接 | | checkBoxIsChecked | boolean | checkbox 默认是否勾选 | | checkBoxIsHidden | boolean | 是否隐藏 checkbox | | privacyBaseColor | string | 协议非点击文案颜色(hex) | | privacyColor | string | 协议点击文案颜色(hex) | | privacyPreText | string | 协议前缀文案(默认"我已阅读并同意") | | privacySufText | string | 协议后缀文案 | | privacyAlignment | number | 协议对齐方式:0=左 1=中 2=右 |

背景

| 参数 | 类型 | 说明 | | --------------- | -------- | ------------------- | | backgroundColor | string | 授权页背景色(hex) |

二次弹窗

未勾选协议时点击登录按钮,弹出二次确认弹窗。

| 参数 | 类型 | 说明 | | --------------------------- | --------- | -------------------------- | | privacyAlertIsNeedShow | boolean | 是否启用二次确认弹窗 | | privacyAlertIsNeedAutoLogin | boolean | 点击弹窗按钮后是否自动登录 | | privacyAlertTitleContent | string | 弹窗标题 | | privacyAlertBtnContent | string | 弹窗按钮文案 |

动画

| 参数 | 类型 | 说明 | | ---------------- | -------- | --------------------------------------------------------- | | presentDirection | number | 授权页弹出方向(仅 iOS):0=底部 1=右 2=顶部 3=左 |

错误码

通过 catch (e) 中的 e.code 获取,可使用 AliAuthErrorCode 常量判断:

| 常量 | 值 | 说明 | | -------------------------- | ------ | ---------------------- | | SUCCESS | 600000 | 成功获取 Token | | LOGIN_PAGE_PRESENT_SUCCESS | 600001 | 授权页唤起成功 | | LOGIN_PAGE_PRESENT_FAILED | 600002 | 授权页唤起失败 | | GET_OPERATOR_INFO_FAILED | 600004 | 获取运营商配置信息失败 | | NO_SIM_CARD | 600007 | 未检测到 SIM 卡 | | NO_CELLULAR_NETWORK | 600008 | 蜂窝网络未开启或不稳定 | | UNKNOWN_OPERATOR | 600009 | 无法判断运营商 | | UNKNOWN_ERROR | 600010 | 未知异常 | | GET_TOKEN_FAILED | 600011 | 获取 Token 失败 | | GET_MASK_PHONE_FAILED | 600012 | 预取号失败 | | TIMEOUT | 600015 | 接口超时 | | AUTH_FAILED | 600017 | AppID/AppKey 解析失败 | | USER_CANCEL | 700000 | 用户点击返回取消登录 | | USER_SWITCH | 700001 | 用户点击切换按钮 | | CLICK_LOGIN_BTN | 700002 | 用户点击登录按钮 | | CLICK_CHECKBOX | 700003 | 用户点击 CheckBox | | CLICK_PROTOCOL | 700004 | 用户点击协议 |

环境要求

  • React Native >= 0.81
  • iOS >= 12.0
  • Android minSdkVersion >= 24
  • Xcode >= 15
  • JDK 17

License

MIT