mirror of
https://github.com/wassname/talk.git
synced 2026-09-12 13:01:11 +08:00
chore: harmonize authToken to accessToken (#2184)
This commit is contained in:
@@ -93,7 +93,7 @@ function createRelayEnvironment() {
|
||||
const tokenGetter: TokenGetter = () => {
|
||||
const localState = source.get(LOCAL_ID);
|
||||
if (localState) {
|
||||
return (localState.loggedIn && localState.authToken) || "";
|
||||
return (localState.loggedIn && localState.accessToken) || "";
|
||||
}
|
||||
return "";
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Child as PymChild } from "pym.js";
|
||||
import { areWeInIframe } from "talk-framework/utils";
|
||||
|
||||
export interface ExternalConfig {
|
||||
authToken?: string;
|
||||
accessToken?: string;
|
||||
}
|
||||
|
||||
export function getExternalConfig(
|
||||
|
||||
@@ -17,5 +17,5 @@ export { graphql } from "react-relay";
|
||||
export {
|
||||
default as commitLocalUpdatePromisified,
|
||||
} from "./commitLocalUpdatePromisified";
|
||||
export { initLocalBaseState, setAuthTokenInLocalState } from "./localState";
|
||||
export { initLocalBaseState, setAccessTokenInLocalState } from "./localState";
|
||||
export { default as fetchQuery } from "./fetchQuery";
|
||||
|
||||
@@ -21,20 +21,20 @@ export const LOCAL_ID = "client:root.local";
|
||||
export const NETWORK_TYPE = "Network";
|
||||
export const NETWORK_ID = "client:root.local.network";
|
||||
|
||||
export function setAuthTokenInLocalState(
|
||||
authToken: string | null,
|
||||
export function setAccessTokenInLocalState(
|
||||
accessToken: string | null,
|
||||
source: RecordSourceProxy
|
||||
) {
|
||||
const localRecord = source.get(LOCAL_ID)!;
|
||||
localRecord.setValue(authToken || "", "authToken");
|
||||
if (authToken) {
|
||||
const { payload, expired } = parseJWT(authToken);
|
||||
localRecord.setValue(payload.exp, "authExp");
|
||||
localRecord.setValue(payload.jti, "authJTI");
|
||||
localRecord.setValue(accessToken || "", "accessToken");
|
||||
if (accessToken) {
|
||||
const { payload, expired } = parseJWT(accessToken);
|
||||
localRecord.setValue(payload.exp, "accessTokenExp");
|
||||
localRecord.setValue(payload.jti, "accessTokenJTI");
|
||||
localRecord.setValue(!expired, "loggedIn");
|
||||
} else {
|
||||
localRecord.setValue(null, "authExp");
|
||||
localRecord.setValue(null, "authJTI");
|
||||
localRecord.setValue(null, "accessTokenExp");
|
||||
localRecord.setValue(null, "accessTokenJTI");
|
||||
localRecord.setValue(false, "loggedIn");
|
||||
}
|
||||
}
|
||||
@@ -42,10 +42,10 @@ export function setAuthTokenInLocalState(
|
||||
export async function initLocalBaseState(
|
||||
environment: Environment,
|
||||
{ localStorage }: TalkContext,
|
||||
authToken?: string | null
|
||||
accessToken?: string | null
|
||||
) {
|
||||
if (authToken === undefined) {
|
||||
authToken = await localStorage!.getItem("authToken");
|
||||
if (accessToken === undefined) {
|
||||
accessToken = await localStorage!.getItem("accessToken");
|
||||
}
|
||||
|
||||
commitLocalUpdate(environment, s => {
|
||||
@@ -56,7 +56,7 @@ export async function initLocalBaseState(
|
||||
root.setLinkedRecord(localRecord, "local");
|
||||
|
||||
// Set auth token
|
||||
setAuthTokenInLocalState(authToken || null, s);
|
||||
setAccessTokenInLocalState(accessToken || null, s);
|
||||
|
||||
// Create network Record
|
||||
const networkRecord = createAndRetain(
|
||||
|
||||
Reference in New Issue
Block a user