connect retries limit, query fix, session fix
This commit is contained in:
parent
fce7ffb972
commit
d0ccd661e3
|
@ -28,7 +28,7 @@ generates:
|
|||
|
||||
# Generate types for notifier
|
||||
src/graphql/schema/notifier.gen.ts:
|
||||
schema: 'https://notifier.discours.io' # FIXME: https
|
||||
schema: 'https://notifier.discours.io'
|
||||
plugins:
|
||||
- 'typescript'
|
||||
- 'typescript-operations'
|
||||
|
|
|
@ -37,32 +37,40 @@ export const ConnectProvider = (props: { children: JSX.Element }) => {
|
|||
const addHandler = (handler: MessageHandler) => {
|
||||
setHandlers((hhh) => [...hhh, handler])
|
||||
}
|
||||
|
||||
const [retried, setRetried] = createSignal<number>(0)
|
||||
const listen = () => {
|
||||
if (isAuthenticated()) {
|
||||
fetchEventSource('https://connect.discours.io', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: getToken(),
|
||||
},
|
||||
onmessage(event) {
|
||||
const m: SSEMessage = JSON.parse(event.data)
|
||||
console.log('[context.connect] Received message:', m)
|
||||
if (isAuthenticated() && !connected() && retried() < 4) {
|
||||
try {
|
||||
fetchEventSource('https://connect.discours.io', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: getToken(),
|
||||
},
|
||||
onmessage(event) {
|
||||
const m: SSEMessage = JSON.parse(event.data)
|
||||
console.log('[context.connect] Received message:', m)
|
||||
|
||||
// Iterate over all registered handlers and call them
|
||||
messageHandlers().forEach((handler) => handler(m))
|
||||
},
|
||||
onclose() {
|
||||
console.log('[context.connect] sse connection closed by server')
|
||||
setConnected(false)
|
||||
},
|
||||
onerror(err) {
|
||||
console.error('[context.connect] sse connection closed by error', err)
|
||||
setConnected(false)
|
||||
throw new Error(err) // NOTE: simple hack to close the connection
|
||||
},
|
||||
})
|
||||
// Iterate over all registered handlers and call them
|
||||
messageHandlers().forEach((handler) => handler(m))
|
||||
},
|
||||
onclose() {
|
||||
console.log('[context.connect] sse connection closed by server')
|
||||
setConnected(false)
|
||||
},
|
||||
onerror(err) {
|
||||
console.error('[context.connect] sse connection closed by error', err)
|
||||
setConnected(false)
|
||||
throw new Error(err) // NOTE: simple hack to close the connection
|
||||
},
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
setRetried((r) => r + 1)
|
||||
if (retried() + 1 > 3) {
|
||||
console.warn('not trying to reconnect anymore, listen() should be called again')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,8 @@ export const InboxProvider = (props: { children: JSX.Element }) => {
|
|||
const [messages, setMessages] = createSignal<Message[]>([])
|
||||
const handleMessage = (sseMessage: SSEMessage) => {
|
||||
console.log('[context.inbox]:', sseMessage)
|
||||
// TODO: handle all action types: create update delete join left
|
||||
|
||||
// handling all action types: create update delete join left seen
|
||||
if (sseMessage.entity === 'message') {
|
||||
const relivedMessage = sseMessage.payload
|
||||
setMessages((prev) => [...prev, relivedMessage])
|
||||
|
|
|
@ -70,7 +70,7 @@ export const SessionProvider = (props: { children: JSX.Element }) => {
|
|||
const authResult = await authorizer().getSession({
|
||||
Authorization: token,
|
||||
})
|
||||
if (authResult) {
|
||||
if (authResult && authResult.access_token) {
|
||||
console.log(authResult)
|
||||
setToken(authResult.access_token)
|
||||
loadSubscriptions()
|
||||
|
@ -113,13 +113,16 @@ export const SessionProvider = (props: { children: JSX.Element }) => {
|
|||
const isAuthenticated = createMemo(() => Boolean(session()?.user))
|
||||
|
||||
const signIn = async (params: LoginInput) => {
|
||||
const authResult = await authorizer().login(params)
|
||||
if (authResult) {
|
||||
const authResult: AuthToken | void = await authorizer().login(params)
|
||||
|
||||
if (authResult && authResult.access_token) {
|
||||
setToken(authResult.access_token)
|
||||
mutate(authResult)
|
||||
loadSubscriptions()
|
||||
console.debug('signed in')
|
||||
} else {
|
||||
console.info((authResult as AuthToken).message)
|
||||
}
|
||||
loadSubscriptions()
|
||||
console.debug('signed in')
|
||||
}
|
||||
|
||||
const [isAuthWithCallback, setIsAuthWithCallback] = createSignal(null)
|
||||
|
|
|
@ -2,7 +2,7 @@ import { gql } from '@urql/core'
|
|||
|
||||
export default gql`
|
||||
query AuthorsFollowedByQuery($slug: String, $user: String, $author_id: Int) {
|
||||
get_authors_followed(slug: $slug, user: $user, author_id: $author_id) {
|
||||
get_author_followers(slug: $slug, user: $user, author_id: $author_id) {
|
||||
id
|
||||
slug
|
||||
name
|
||||
|
|
Loading…
Reference in New Issue
Block a user