-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathsession.js
More file actions
33 lines (27 loc) · 834 Bytes
/
session.js
File metadata and controls
33 lines (27 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// @flow
import type { AsyncStorage } from './storage'
import { getData, updateStorage } from './storage'
export type webIdOidcSession = {
idp: string,
webId: string,
accessToken: string,
idToken: string,
clientId: string,
sessionKey: string,
}
export type Session = webIdOidcSession
export async function getSession(storage: AsyncStorage): Promise<?Session> {
const data = await getData(storage)
return data.session || null
}
export function saveSession(
storage: AsyncStorage
): (session: Session) => Promise<Session> {
return async (session) => {
const data = await updateStorage(storage, (data) => ({ ...data, session }))
return data.session
}
}
export async function clearSession(storage: AsyncStorage): Promise<void> {
await updateStorage(storage, (data) => ({ ...data, session: null }))
}