Skip to content

Commit

Permalink
chore: add access token to testing app (#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 authored Apr 29, 2024
1 parent c5ceaa0 commit 6c7ec19
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions apps/testing/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VITE_APP_ID=
VITE_USER_ID=
VITE_ACCESS_TOKEN=
10 changes: 5 additions & 5 deletions apps/testing/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import GroupChannelApp from '../../../src/modules/App';
import OpenChannelApp from '../../../src/modules/OpenChannelApp';

import { useConfigParams } from './utils/paramsBuilder.ts';
import { InitialParams, useConfigParams } from './utils/paramsBuilder.ts';
import { URLBuilder } from './URLBuilder.tsx';

const defaultProps = {
const defaultProps: InitialParams = {
appId: import.meta.env.VITE_APP_ID,
userId: 'test',
nickname: 'User',
userId: import.meta.env.VITE_USER_ID ?? 'test',
accessToken: import.meta.env.VITE_ACCESS_TOKEN,
};

function GroupChannelPage() {
const props = useConfigParams(defaultProps);
return <GroupChannelApp {...props} breakpoint={/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)} />;
return <GroupChannelApp {...props} breakpoint={/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)} />;
}

function OpenChannelPage() {
Expand Down
8 changes: 6 additions & 2 deletions apps/testing/src/utils/paramsBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { UIKitOptions } from '../../../../src/lib/types.ts';
import { useSearchParams } from 'react-router-dom';

interface InitialParams {
export interface InitialParams {
appId?: string;
userId?: string;
nickname?: string;
accessToken?: string;
}

interface ParamsAsProps {
appId: string;
userId: string;
nickname: string;
accessToken?: string;
allowProfileEdit: boolean;
isMultipleFilesMessageEnabled: boolean;
uikitOptions: UIKitOptions;
Expand All @@ -22,14 +24,16 @@ export const useConfigParams = (initParams: InitialParams): ParamsAsProps => {
const response = {
appId: searchParams.get('appId') || initParams.appId,
userId: searchParams.get('userId') || initParams.userId,
nickname: searchParams.get('nickname') || initParams.nickname,
nickname: searchParams.get('nickname') || initParams.nickname || initParams.userId,
accessToken: searchParams.get('accessToken') || initParams.accessToken,
allowProfileEdit: parseValue(searchParams.get('enableProfileEdit')) ?? true,
isMultipleFilesMessageEnabled: parseValue(searchParams.get('enableMultipleFilesMessage')) ?? true,
uikitOptions: {},
} as ParamsAsProps;

if (!response.appId) throw new Error(`Invalid app id: ${response.appId}`);
if (!response.userId) throw new Error(`Invalid user id: ${response.userId}`);
if (!response.accessToken) delete response.accessToken;

paramKeys.forEach((key) => {
const value = searchParams.get(key);
Expand Down

0 comments on commit 6c7ec19

Please sign in to comment.