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
export default function protectedPage(UI) { | |
return observer(class ProtectedPage extends Component { | |
componentDidMount() { | |
this.disposer = autorun(() => { | |
if (typeof window !== 'undefined' | |
&& !getAuthStore().authIsPending | |
&& !getAuthStore().isAuthenticated | |
) { | |
Router.push('/access-denied') |
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
@observable user = null | |
@observable authIsPending = true | |
constructor () { | |
this.unwatchAuth = auth.onAuthStateChanged(user => { | |
this.user = user | |
this.authIsPending = false | |
}) | |
} |
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
@action start = () => { | |
when( | |
() => this.authStore.user, | |
() => { | |
const userId = this.authStore.user.uid; | |
const ref = db.ref(`/hashes/${userId}`); | |
ref.on('child_added', (data) => { | |
this.hashes.set(data.key, data.val()); | |
}); | |
} |
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
@action start = () => { | |
const disposer = autorun(() => { | |
if (this.authStore.user) { | |
// stop autorun | |
disposer() | |
// get current userId | |
const userId = this.authStore.user.uid | |
// save ref so we cann fire .off() on unmount | |
this.ref = db.ref(`/hashes/${userId}`) | |
// get initial values one - so we can distinguish between "no data" and "not loaded" |
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
const HashInput = ({ callback }) => ( | |
<div> | |
<input type="text" onChange={e => callback(e.target.value)}/> | |
</div> | |
); | |
export default HashInput; |
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
@action start = () => { | |
const disposer = autorun(() => { | |
if (this.authStore.user) { | |
disposer(); | |
const userId = this.authStore.user.uid; | |
const ref = db.ref(`/hashes/${userId}`); | |
ref.on('child_added', (data) => { | |
this.hashes.set(data.key, data.val()); | |
}); | |
} |
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
class Store { | |
@observable hash = ''; | |
@observable hashes = observable.map([]); | |
constructor() { | |
this.authStore = initAuthStore(false); | |
} | |
@action start = () => { | |
const userId = this.authStore.user.uid; |
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
path /hashes/{userid} { | |
read() {isCurrentUser(userid)} | |
} | |
path /hashes/{userid}/{id} is Hash { | |
read() {isCurrentUser(userid)} | |
write() {isCurrentUser(userid)} | |
} | |
type Hash { | |
text: String, |
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
path /hashes/{userid} { | |
read() {isCurrentUser(userid)} | |
} | |
path /hashes/{userid}/{id} { | |
read() {isCurrentUser(userid)} | |
write() {isCurrentUser(userid)} | |
} | |
isCurrentUser(uid) { auth != null && auth.uid == uid } |
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
let store = null; | |
class Store { | |
@observable user = null; | |
constructor() { | |
auth.onAuthStateChanged(user => { | |
this.user = user; | |
}); | |
} |