11import { feathers } from 'feathers'
22import { fetchClient } from 'feathers/client'
33import { getLoginElement } from 'talon-auth'
4+ import type { Client } from '../../api/src/app.js'
45
5- // Initialize our Feathers client application through Socket.io
6- // with hooks and authentication.
7- const client = feathers ( )
6+ const client : Client = feathers ( )
87
98client . configure ( fetchClient ( window . fetch . bind ( window ) , {
109 baseUrl : 'http://localhost:3030' ,
@@ -14,10 +13,11 @@ client.configure(fetchClient(window.fetch.bind(window), {
1413client . hooks ( [
1514 async ( context , next ) => {
1615 const login = await getLoginElement ( )
17- const header = await login ?. getHeader ( )
16+ const authorization = await login ?. getHeader ( )
17+
1818 context . params . headers = {
1919 ...context . params . headers ,
20- authorization : header
20+ authorization
2121 }
2222 return next ( )
2323 }
@@ -132,8 +132,6 @@ addEventListener('#send-message', 'submit', async (ev) => {
132132client . service ( 'messages' ) . on ( 'created' , addMessage )
133133
134134const init = async ( ) => {
135- document . getElementById ( 'app' ) . innerHTML = chatTemplate ( )
136-
137135 await client . setup ( )
138136
139137 // Find the latest 25 messages. They will come with the newest first
@@ -143,6 +141,8 @@ const init = async () => {
143141 }
144142 } )
145143
144+ document . getElementById ( 'app' ) . innerHTML = chatTemplate ( )
145+
146146 // We want to show the newest message last
147147 for ( const message of messages . data . reverse ( ) ) {
148148 await addMessage ( message )
0 commit comments