Code Monkey home page Code Monkey logo

sign-in-with-blockstack-react's Introduction

Sign In with Blockstack Button (React Component)

Image of Sign in with Blockstack react component

Installing

npm install blockstack-signin-btn --save

Use

There are two components in this library: SignInBlockstackButton and SignInBlockstackLiteButton. SignInBlockstackButton has the blockstack sign in and sign out functions written. These functions are passed into SignInBlockstackLiteButton as props. SignInBlockstackButton uses SignInBlockstackLiteButton. Reference the code for more.

Importing

At the top of the file, include:

import { SignInBlockstackButton, SignInBlockstackLiteButton } from 'blockstack-signin-btn';

Minimum

This is the bare minimum. You should reference the blockstack.js library to check if the user is logged in with blockstack.isUserSignedIn() and pass that to isSignedIn.

<SignInBlockstackButton />

Customize Button Text

You can change the button text from the default of Sign In with Blockstack and Sign Out. You pass in your wanted text as props:

<SignInBlockstackButton
  signInBtnText="New Sign In Text"
  signOutBtnText="New Sign Out Text"
/>

Hide the Blockstack Logo in Button

We include the Blockstack logo on the left side of the button. You can hide this, just pass in the prop includeBlockstackLogo as false.

<SignInBlockstackButton
  includeBlockstackLogo={false}
/>

Custom Redirect on Sign Out

This is just for SignInBlockstackButton and not the lite. Since the sign out function is already written, by default it redirects after sign out to /. This can be changed with signOutRedirect.

<SignInBlockstackButton
  signOutRedirect="/custom-signout-page"
/>

Render Nothing

This was included in case the developer want to not render a sign in or sign out button. The user may be pending sign in, etc.

<SignInBlockstackButton
  renderNothing
/>

// or

<SignInBlockstackButton
  renderNothing={true}
/>

Custom Styling

All styling has been done inline to control the areas to manipulate and name issues. All aspects of the button can be customized in terms of styling. The text can be styled with textStyle prop. The image/logo can be styled with imageStyle prop. The sign out button can be styled with signOutStyle prop. The sign in button can be styled with signInStyle prop. Both buttons can be styled with style prop. You can remove default styling with defaultStyle prop.

<SignInBlockstackButton
  textStyle={{
    fontSize: 24,
  }}
  imageStyle={{
    height: 100,
  }}
  signOutStyle={{
    backgroundColor: 'red',
  }}
  signInStyle={{
    backgroundColor: 'green',
  }}
/>

// or for both buttons at once and remove default

<SignInBlockstackButton
  textStyle={{
    color: '#2e2e2e',
  }}
  style={{
    backgroundColor: '#fff',
  }}
  defaultStyle={{}}
/>

Testing

To test this component, we will use a link to a pre built demo project. In a terminal window:

git clone https://github.com/alanbsmith/component-lib-playground.git
cd component-lib-playground/
npm install

In another terminal:

git clone https://github.com/keithweaver/Sign-in-with-Blockstack-react.git
cd Sign-in-with-Blockstack-react
npm install
npm link

Returning to the first terminal window, you should then run:

npm link blockstack-signin-btn
npm run dev

An app will be running on http://localhost:8080 and you will be able to add blockstack-signin-btn to it. If you open src/components/App.js and add import { SignInBlockstackButton } from 'blockstack-signin-btn'; to the top. Then add code below to the render. It will add the button. This request will however fail because you need the manifest.json and other Blockstack parts.

<SignInBlockstackButton />

Reference

sign-in-with-blockstack-react's People

Contributors

keithweaver avatar

Watchers

Jeremy Sarda avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.