Skip to content

Instantly share code, notes, and snippets.

@corydolphin
Created February 27, 2015 04:03
Show Gist options
  • Save corydolphin/5fb4e89049b9306e80f9 to your computer and use it in GitHub Desktop.
Save corydolphin/5fb4e89049b9306e80f9 to your computer and use it in GitHub Desktop.
A simple React component for Digits Login
React = require 'react'
Request = require 'superagent'
Digits = require 'sdk'
Digits.init(consumerKey:"3evG1ZwmgzY2FiJ1NihrbfqSt")
DigitsLoginButton = React.createClass
propTypes:
userUpdated: React.PropTypes.func.isRequired
componentDidMount: ()->
Digits.getLoginStatus()
.done @onLoginSuccess
.fail @onLoginFailure
onLoginSuccess: (resp)->
console.log resp
digits_oauth_header = resp.oauth_echo_headers.oauth_echo_header ? resp.oauth_echo_headers['X-Verify-Credentials-Authorization']
Request
.get 'http://localhost:5000/api/v1/users/'
.set Authorization: digits_oauth_header
.end (res) ->
console.log res.body
@props.userUpdated res
onLoginFailure: (response)->
console.log response
@props.userUpdated response
onLoginClicked: (e)->
Digits.logIn()
.done @onLoginSuccess
.fail @onLoginFailure
render: () ->
React.createElement 'button', {onClick:@onLoginClicked}, 'Login with Digits'
module.exports = DigitsLoginButton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment