Skip to content

Commit

Permalink
fix: type definition of user object for ws auth (#1003)
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz authored Aug 29, 2023
1 parent c9624cd commit e0ed3d1
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 10 deletions.
6 changes: 3 additions & 3 deletions packages/client/src/coordinator/connection/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { ConnectedEvent, UserRequest, VideoEvent } from '../../gen/coordinator';
export type UR = Record<string, unknown>;

export type User =
| (UserRequest & { type?: 'authenticated' })
| (UserRequest & { type: 'guest' })
| (Omit<UserRequest, 'id'> & {
| (Omit<UserRequest, 'role'> & { type?: 'authenticated' })
| (Omit<UserRequest, 'role'> & { type: 'guest' })
| (Omit<UserRequest, 'id' | 'role'> & {
id?: '!anon';
type: 'anonymous';
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ const tokenProviderUrl = import.meta.env.VITE_TOKEN_PROVIDER_URL as string;

type VideoClientProviderProps = {
isAnon?: boolean;
role?: string;
};

export const useInitVideoClient = ({
isAnon,
role,
}: PropsWithChildren<VideoClientProviderProps>) => {
const { callId } = useParams<{ callId: string }>();
const { api_key, token, type } = getURLCredentials();
Expand Down Expand Up @@ -48,7 +46,7 @@ export const useInitVideoClient = ({
apiKey,
...((isAnon || !token) && { tokenProvider }),
...(!isAnon && { token }),
user: isAnon ? { type: 'anonymous' } : role ? { ...user, role } : user,
user: isAnon ? { type: 'anonymous' } : user,
});
setClient(_client);

Expand Down
2 changes: 1 addition & 1 deletion sample-apps/react/livestream-app/src/hosts/Hosts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Outlet } from 'react-router-dom';
import { useInitVideoClient } from '../hooks/useInitVideoClient';

export const Hosts = () => {
const client = useInitVideoClient({ role: 'host' });
const client = useInitVideoClient({});

if (!client) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion sample-apps/react/livestream-app/src/viewers/Viewers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ErrorPanel, LoadingPanel } from '../LoadingState';

export const Viewers = () => {
const { callId } = useParams<{ callId?: string }>();
const client = useInitVideoClient({ role: 'user' });
const client = useInitVideoClient({});

if (!client) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const KichinSink: Props = {
user: {
id: '123213',
name: 'Kichin Sink',
role: 'role',
teams: ['team'],
image: '',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export const KichinSink: Props = {
user: {
id: '123213',
name: 'Kichin Sink',
role: 'role',
teams: ['team'],
image: '',
},
Expand Down

0 comments on commit e0ed3d1

Please sign in to comment.