Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spike of firebase auth/signin and file upload to cloud storage
- Loading branch information
presstube
committed
Apr 18, 2017
1 parent
f509f16
commit 526ae87
Showing
6 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
{ | ||
"origin": ["*"], | ||
"method": ["GET"], | ||
"maxAgeSeconds": 3600 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
import * as firebase from "firebase" | ||
import * as firebaseui from "firebaseui" | ||
|
||
const config = { | ||
apiKey: "AIzaSyBxE0HZfnB7uF2J57oTmjFX-0mLeBfJI-0", | ||
authDomain: "cloudstoragespike.firebaseapp.com", | ||
databaseURL: "https://cloudstoragespike.firebaseio.com", | ||
projectId: "cloudstoragespike", | ||
storageBucket: "cloudstoragespike.appspot.com", | ||
messagingSenderId: "10638532760" | ||
} | ||
|
||
firebase.initializeApp(config) | ||
|
||
|
||
// document.addEventListener('keydown', e => { | ||
// // console.log('keydown: ', e.key) | ||
// if (e.key == 'S') { | ||
// uploadAnimData('bongo.json', { | ||
// blah: 'bongobongo', | ||
// bloo: 123, | ||
// blee: [1, 2, 3] | ||
// }) | ||
// } | ||
// }) | ||
|
||
const uiConfig = { | ||
signInSuccessURL: '', | ||
signInOptions: [ | ||
firebase.auth.GoogleAuthProvider.PROVIDER_ID, | ||
], | ||
tosURL: 'myTOS.txt', | ||
callbacks: { | ||
signInSuccess: (currentUser, credential, redirectUrl) => { | ||
// Do something. | ||
// Return type determines whether we continue the redirect automatically | ||
// or whether we leave that to developer to handle. | ||
// console.log('signin success') | ||
return false // to allow the success page to be same as signin | ||
}, | ||
} | ||
}, | ||
ui = new firebaseui.auth.AuthUI(firebase.auth()) | ||
|
||
firebase.auth().onAuthStateChanged(function(user) { | ||
if (user) { | ||
// firebase.auth().signOut() | ||
console.log('already signed in') | ||
} else { | ||
ui.start('#firebaseui-auth-container', uiConfig) | ||
} | ||
}); | ||
|
||
|
||
const uploadAnimData = (filename, animData) => { | ||
const uploadRef = firebase.storage().ref().child('animData/' + filename), | ||
file = new Blob([JSON.stringify(animData)], {type: 'application/json'}) | ||
|
||
return uploadRef.put(file).then(function(snapshot) { | ||
console.log('upload succeeded whoooo: ', snapshot.downloadURL) | ||
}) | ||
} | ||
|
||
export {uploadAnimData} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import _ from 'lodash' | ||
import './norman' | ||
import './norman' | ||
// import './firebasesavespike' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters