mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-11-20 03:25:52 +01:00
Actually store in storage
This commit is contained in:
parent
15fd73ed9c
commit
44f20d54b0
@ -337,6 +337,16 @@ export class Client {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the access token in use by the client.
|
||||
* Will also update the token in session storage.
|
||||
* @param {string} token A Matrix Access Token
|
||||
*/
|
||||
async updateAccessToken(token) {
|
||||
this._session.updateAccessToken(token);
|
||||
await this._platform.sessionInfoStorage.updateAccessToken(this._sessionId, token);
|
||||
}
|
||||
|
||||
async _waitForFirstSync() {
|
||||
this._sync.start();
|
||||
this._status.set(LoadStatus.FirstSync);
|
||||
|
@ -37,6 +37,7 @@ interface ISessionInfo {
|
||||
interface ISessionInfoStorage {
|
||||
getAll(): Promise<ISessionInfo[]>;
|
||||
updateLastUsed(id: string, timestamp: number): Promise<void>;
|
||||
updateAccessToken(id: string, token: string): Promise<void>;
|
||||
get(id: string): Promise<ISessionInfo | undefined>;
|
||||
add(sessionInfo: ISessionInfo): Promise<void>;
|
||||
delete(sessionId: string): Promise<void>;
|
||||
@ -60,14 +61,22 @@ export class SessionInfoStorage implements ISessionInfoStorage {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
async updateAccessToken(id: string, accessToken: string): Promise<void> {
|
||||
const sessions = await this.getAll();
|
||||
const session = sessions.find(session => session.id === id);
|
||||
if (!session) {
|
||||
throw Error('No session found');
|
||||
}
|
||||
session.accessToken = accessToken;
|
||||
localStorage.setItem(this._name, JSON.stringify(sessions));
|
||||
}
|
||||
|
||||
async updateLastUsed(id: string, timestamp: number): Promise<void> {
|
||||
const sessions = await this.getAll();
|
||||
if (sessions) {
|
||||
const session = sessions.find(session => session.id === id);
|
||||
if (session) {
|
||||
session.lastUsed = timestamp;
|
||||
localStorage.setItem(this._name, JSON.stringify(sessions));
|
||||
}
|
||||
const session = sessions.find(session => session.id === id);
|
||||
if (session) {
|
||||
session.lastUsed = timestamp;
|
||||
localStorage.setItem(this._name, JSON.stringify(sessions));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user