Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feathers-dove] using the createClient function #2713

Closed
juni0r opened this issue Aug 3, 2022 · 4 comments
Closed

[feathers-dove] using the createClient function #2713

juni0r opened this issue Aug 3, 2022 · 4 comments

Comments

@juni0r
Copy link

juni0r commented Aug 3, 2022

A newly generated app will have a client.ts file:

import { feathers } from '@feathersjs/feathers'
import type { PostsData, PostsResult, PostsQuery } from './services/posts/posts.schema'
import type { Service, TransportConnection, Params } from '@feathersjs/feathers'

export interface ServiceTypes {
  posts: Service<PostsData, PostsResult, Params<PostsQuery>>
  // A mapping of client side services
}

export const createClient = <Configuration = any>(connection: TransportConnection<ServiceTypes>) => {
  const client = feathers<ServiceTypes, Configuration>()

  client.configure(connection)

  return client
}

I'm completely at loss on how to use createClient to obtain a REST or SocketIO client. The documentation on the client contains examples like

import io from 'socket.io-client'
import { feathers } from '@feathersjs/feathers'
import socketio from '@feathersjs/socketio-client'

const socket = io('http://api.my-feathers-server.com')
const client = feathers()

client.configure(socketio(socket))

But trying to use this with createClient(socketio(socket)) won't work since the methos expects a TransportConnection<ServiceTypes>. I don't even understand what this type represents (the type definition is not very enlightening).

Some examples would be greatly appreciated.

@daffl
Copy link
Member

daffl commented Aug 3, 2022

A working example can be found at https://github.com/feathersjs/feathers-chat/blob/dove/react-chat/src/feathers.ts - I will also add it to the CLI guide at https://dove.feathersjs.com/guides/cli/index.html shortly. Note that there was a bug on how the client is generated which will be fixed in the next prerelease (5.0.0-pre.28) via #2701

@juni0r juni0r changed the title [feathers-dove] using the createClient functio [feathers-dove] using the createClient function Aug 3, 2022
@juni0r
Copy link
Author

juni0r commented Aug 3, 2022

Ok, so I tried

import io from 'socket.io-client';
import socketio from '@feathersjs/socketio-client';
import authentication from '@feathersjs/authentication-client';
import { createClient } from './client';

const connection = socketio(io('http://localhost:3030'));
const client = createClient(connection);

client.configure(authentication() as any);

which results in
image

@daffl
Copy link
Member

daffl commented Aug 3, 2022

I just published v5.0.0-pre.28 with a bunch of fixes around this. Would you mind installing it and trying this with a newly generated app?

@juni0r
Copy link
Author

juni0r commented Aug 3, 2022

My bad: I forgot to use @pre when I installed @feathersjs/authentication-client.

I now installed all packages from pre.28 and it works.

Thank you very much!

@juni0r juni0r closed this as completed Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants