auth-refresh-fix
This commit is contained in:
parent
fce3d9cf21
commit
6b87cc9a34
|
@ -56,7 +56,7 @@ export const NotificationsProvider = (props: { children: JSX.Element }) => {
|
||||||
setTotalNotificationsCount(total)
|
setTotalNotificationsCount(total)
|
||||||
setUnreadNotificationsCount(unread)
|
setUnreadNotificationsCount(unread)
|
||||||
setNotificationEntities(newGroupsEntries)
|
setNotificationEntities(newGroupsEntries)
|
||||||
console.debug(`[context.notifications] groups updated`)
|
console.debug(`[context.notifications] groups updated`, groups)
|
||||||
return groups
|
return groups
|
||||||
} else {
|
} else {
|
||||||
return []
|
return []
|
||||||
|
|
|
@ -17,6 +17,7 @@ import {
|
||||||
createResource,
|
createResource,
|
||||||
createSignal,
|
createSignal,
|
||||||
on,
|
on,
|
||||||
|
onCleanup,
|
||||||
onMount,
|
onMount,
|
||||||
useContext,
|
useContext,
|
||||||
} from 'solid-js'
|
} from 'solid-js'
|
||||||
|
@ -105,6 +106,7 @@ export const SessionProvider = (props: {
|
||||||
})
|
})
|
||||||
|
|
||||||
// load
|
// load
|
||||||
|
let ta
|
||||||
const [configuration, setConfig] = createSignal<ConfigType>(defaultConfig)
|
const [configuration, setConfig] = createSignal<ConfigType>(defaultConfig)
|
||||||
const authorizer = createMemo(() => new Authorizer(defaultConfig))
|
const authorizer = createMemo(() => new Authorizer(defaultConfig))
|
||||||
const [isSessionLoaded, setIsSessionLoaded] = createSignal(false)
|
const [isSessionLoaded, setIsSessionLoaded] = createSignal(false)
|
||||||
|
@ -112,8 +114,11 @@ export const SessionProvider = (props: {
|
||||||
const [session, { refetch: loadSession, mutate: setSession }] = createResource<AuthToken>(
|
const [session, { refetch: loadSession, mutate: setSession }] = createResource<AuthToken>(
|
||||||
async () => {
|
async () => {
|
||||||
try {
|
try {
|
||||||
console.info('[context.session] loading session')
|
const s = await authorizer().getSession()
|
||||||
return await authorizer().getSession()
|
console.info('[context.session] loading session', s)
|
||||||
|
ta = setTimeout(loadSession, s.expires_in * 1000)
|
||||||
|
console.info(`[context.session] will refresh in ${s.expires_in / 60} mins`)
|
||||||
|
return s
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.info('[context.session] cannot refresh session', e)
|
console.info('[context.session] cannot refresh session', e)
|
||||||
setAuthError(e)
|
setAuthError(e)
|
||||||
|
@ -126,6 +131,10 @@ export const SessionProvider = (props: {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
clearTimeout(ta)
|
||||||
|
})
|
||||||
|
|
||||||
const [author, { refetch: loadAuthor, mutate: setAuthor }] = createResource<Author | null>(
|
const [author, { refetch: loadAuthor, mutate: setAuthor }] = createResource<Author | null>(
|
||||||
async () => {
|
async () => {
|
||||||
const u = session()?.user
|
const u = session()?.user
|
||||||
|
@ -148,7 +157,7 @@ export const SessionProvider = (props: {
|
||||||
if (session()) {
|
if (session()) {
|
||||||
const token = session()?.access_token
|
const token = session()?.access_token
|
||||||
if (token) {
|
if (token) {
|
||||||
console.log('[context.session] token observer got token', token)
|
// console.log('[context.session] token observer got token', token)
|
||||||
if (!inboxClient.private) {
|
if (!inboxClient.private) {
|
||||||
apiClient.connect(token)
|
apiClient.connect(token)
|
||||||
notifierClient.connect(token)
|
notifierClient.connect(token)
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"query": "query ValidateToken($params: ValidateJWTTokenInput!) { validate_jwt_token(params: $params) { is_valid claims } }",
|
|
||||||
"variables": {
|
|
||||||
"params": {
|
|
||||||
"token_type": "access_token",
|
|
||||||
"token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhbGxvd2VkX3JvbGVzIjpbInJlYWRlciJdLCJhdWQiOiI5YzExMzM3Ny01ZWVhLTRjODktOThlMS02OTMwMjQ2MmZjMDgiLCJleHAiOjE3MDI1MDM3NDksImlhdCI6MTcwMjUwMTk0OSwiaXNzIjoiaHR0cHM6Ly9hdXRoLmRpc2NvdXJzLmlvIiwibG9naW5fbWV0aG9kIjoiYmFzaWNfYXV0aCIsIm5vbmNlIjoiNTNhZmE1NzMtMWZhMC00NDNhLTk4NzktNWE0ZDk3YTQ1OWEzIiwicm9sZXMiOlsicmVhZGVyIl0sInNjb3BlIjpbIm9wZW5pZCIsImVtYWlsIiwicHJvZmlsZSJdLCJzdWIiOiIyNDU3NTc5Yi0yNTk3LTQzNjMtOGU1MC00YWM5ZjY5YzgyMWQiLCJ0b2tlbl90eXBlIjoiYWNjZXNzX3Rva2VuIn0.ImAmAFXkwReYhLvLR1GG3g0mDllQaj7NVWw5q9D7EFUHtpjuNOanlVfzoaqqB6CXkc_uSRlrfiaLkbfCzhbXAWpi49vOI9P2fvLv-41Y0p8FJZnruZDi1c8psyPU5gpCLp3nqtBTTIR2IP-Uu_1oYo2Hl02xdOFjVHw19f-WEf73L6APBPppNeE21IJJy8aU5uXBHv12Y--kH5tEzn83BNBKPm5yWay-k4DVuBnAJt_ODENqm5NAaiG-q2eG3GnXWpjgpDXf0cxVXdtJbvFcPIv-pH7Dm6ae8m4xM7MmVmpzCE5f-Qc1lwcfX51Cr6IMXUjHx0N3n54sKk91CPa_ug"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,6 +5,7 @@ import { createMemo, createSignal } from 'solid-js'
|
||||||
|
|
||||||
import { apiClient } from '../../graphql/client/core'
|
import { apiClient } from '../../graphql/client/core'
|
||||||
import { byTopicStatDesc } from '../../utils/sortby'
|
import { byTopicStatDesc } from '../../utils/sortby'
|
||||||
|
import { useRouter } from '../router'
|
||||||
|
|
||||||
export type TopicsSortBy = 'followers' | 'title' | 'authors' | 'shouts'
|
export type TopicsSortBy = 'followers' | 'title' | 'authors' | 'shouts'
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ const [randomTopics, setRandomTopics] = createSignal<Topic[]>([])
|
||||||
|
|
||||||
const sortedTopics = createLazyMemo<Topic[]>(() => {
|
const sortedTopics = createLazyMemo<Topic[]>(() => {
|
||||||
const topics = Object.values(topicEntities())
|
const topics = Object.values(topicEntities())
|
||||||
|
const { changeSearchParams } = useRouter()
|
||||||
switch (sortAllBy()) {
|
switch (sortAllBy()) {
|
||||||
case 'followers': {
|
case 'followers': {
|
||||||
// console.debug('[store.topics] sorted by followers')
|
// console.debug('[store.topics] sorted by followers')
|
||||||
|
@ -40,7 +41,8 @@ const sortedTopics = createLazyMemo<Topic[]>(() => {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
console.error(`Unknown sort: ${sortAllBy()}`)
|
topics.sort(byTopicStatDesc('shouts'))
|
||||||
|
changeSearchParams({ by: 'shouts' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user