1.1.2 • Published 7 months ago

@dmatora/react-wechat-login v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

react-wechat-login

English | 中文

React component for website login by Wechat

Installation

$ npm install react-wechat-login

Usage

Frontend

import WechatLogin from "react-wechat-login";

const loginWechatRes = (res) => {
  console.log(res);
}

...
<WechatLogin
  appid={YOUR_APP_ID}
  redirectUri="http://localhost:4000/api/wechatlogin"
  onSuccess={loginWechatRes}
/>
...

Backend

**Important:**

In order to transfer the response message between iframe and parent page, the returned html from the backend must call the parent.postMessage(). Please check this example

Customize style of QR

Based on the document on the Wechat Open Platform, you can customize the style of the QR code image by providing the URI of your css file. That means you need to create a css file in the public folder and provide the URI to the css prop.

An example of css file is following:

.impowerBox .qrcode {
  width: 200px;
}
.impowerBox .title {
  display: none;
}
.impowerBox .info {
  width: 200px;
}
.status_icon {
  display: none;
}
.impowerBox .status {
  text-align: center;
}

Props

propsrequiretypedescription
appidYESstringYour appid
redirectUriYESstringYour redirect uri. It must be the same origin of the uri you set in the wechat open platform
onSuccessYESfunctionthe callback funciton after the login
statestringthe state sent back to the backend
styleCSSPropertiesthe style of the iframe element
cssstringthe location of css file for customizing style of QR code

Welcome submit issues

https://github.com/philwu/react-wechat-login/issues

1.1.2

7 months ago

1.1.1

7 months ago