Check for auth session on new object. Add auth link to auth template.

This commit is contained in:
Harry Hedger 2016-02-03 04:04:18 -05:00
parent 6af4293dbe
commit ea81ec9e8c

View file

@ -1,5 +1,7 @@
// import Utils from '../core/Utils'
import Plugin from './Plugin'
// temporarily using superagent
import request from 'superagent'
export default class Drive extends Plugin {
constructor (core, opts) {
@ -8,9 +10,13 @@ export default class Drive extends Plugin {
this.authenticate = this.authenticate.bind(this)
this.connect = this.connect.bind(this)
this.render = this.render.bind(this)
this.renderAuthentication = this.renderAuthentication.bind(this)
this.checkAuthentication = this.checkAuthentication.bind(this)
this.files = []
this.currentDir = '/'
this.checkAuthentication()
this.isAuthenticated = false
}
@ -23,6 +29,16 @@ export default class Drive extends Plugin {
}
}
checkAuthentication () {
request.get('http://localhost:3002/drive/auth/authorize')
.set('Content-Type', 'application/json')
.end((err, res) => {
if (err) { return new Error(err) }
this.isAuthenticated = res.body.isAuthenticated
this.authUrl = res.body.authUrl
})
}
authenticate () {
}
@ -39,7 +55,7 @@ export default class Drive extends Plugin {
}
renderAuthentication () {
return `<div><h1>Authenticate With Google Drive</h1><button>Authenticate</button></div>`
return `<div><h1>Authenticate With Google Drive</h1><a href=${ this.authUrl || '#' }>Authenticate</a></div>`
}
render (files) {