Support authentication

This commit is contained in:
Chi Vinh Le
2018-08-09 16:14:35 +02:00
parent ff62dc4ecc
commit d140e2449f
22 changed files with 357 additions and 15 deletions
@@ -1,6 +1,7 @@
import qs from "query-string";
import { commitLocalUpdate, Environment } from "relay-runtime";
import { TalkContext } from "talk-framework/lib/bootstrap";
import {
createAndRetain,
LOCAL_ID,
@@ -17,7 +18,10 @@ import {
/**
* Initializes the local state, before we start the App.
*/
export default async function initLocalState(environment: Environment) {
export default async function initLocalState(
environment: Environment,
{ localStorage }: TalkContext
) {
commitLocalUpdate(environment, s => {
const root = s.getRoot();
@@ -25,6 +29,9 @@ export default async function initLocalState(environment: Environment) {
const localRecord = createAndRetain(environment, s, LOCAL_ID, LOCAL_TYPE);
root.setLinkedRecord(localRecord, "local");
// Set auth token
localRecord.setValue(localStorage.getItem("authToken") || "", "authToken");
// Parse query params
const query = qs.parse(location.search);