removed instanceURL accept system

This commit is contained in:
Chirag Bhalotia 2023-06-24 22:54:31 +05:30
parent 6fd6bbd982
commit 6bd26d9582
No known key found for this signature in database
GPG Key ID: F7F1F1FBFFD40427
6 changed files with 7 additions and 25 deletions

View File

@ -27,11 +27,11 @@ class ApiSdk {
if (typeof window === 'undefined') {
const { cookies } = await import('next/headers');
config.headers['x-shx-api-key'] = cookies().get('apiKey')?.value;
config.baseURL = cookies().get('instanceUrl')?.value;
} else {
config.headers['x-shx-api-key'] = Cookies.get().apiKey ?? '';
config.baseURL = Cookies.get('instanceUrl') ?? '';
}
config.baseURL = process.env.NEXT_PUBLIC_INSTANCE_URL
return config;
});

View File

@ -2,7 +2,6 @@ import { sidebarGroups } from '@/lib/sidebar';
import { cookies } from 'next/headers';
import Link from 'next/link';
import { redirect } from 'next/navigation';
import React from 'react';
interface DashboardLayoutProps {
children: React.ReactNode;
@ -12,8 +11,7 @@ const Layout = ({ children }: DashboardLayoutProps) => {
const cookieList = cookies();
const apiKey = cookieList.has('apiKey');
const masterKey = cookieList.has('masterKey');
const instanceUrl = cookieList.has('instanceUrl');
if (!apiKey || !masterKey || !instanceUrl) redirect('/');
if (!apiKey || !masterKey) redirect('/');
return (
<div className="flex h-screen">
<div className="sidebar w-full max-w-xs h-screen bg-black flex flex-col overflow-x-hidden overflow-y-auto">

View File

@ -22,7 +22,6 @@ function ApiKeyList({ data }: ApiKeyListProps) {
if (apiKey.endsWith(key.substring(9))) {
Cookies.remove('apiKey');
Cookies.remove('masterKey');
Cookies.remove('instanceUrl');
router.replace('/');
}
setApiKeys(old => old.filter(key => key.keyID !== id));

View File

@ -27,7 +27,7 @@ function ShortenUrlList({ data }: ShortenUrlListProps) {
state: false,
});
const [input, setInput] = useState('');
const [instanceUrl, setInstanceURL] = useState('');
const onAddURL = async (url: string) => {
try {
await api.url.uploadUrl(url);
@ -59,9 +59,6 @@ function ShortenUrlList({ data }: ShortenUrlListProps) {
}
};
useEffect(() => {
setInstanceURL(Cookies.get('instanceUrl') ?? '');
}, []);
return (
<>
<URLControls onAddURL={onAddURL} />
@ -103,10 +100,10 @@ function ShortenUrlList({ data }: ShortenUrlListProps) {
</td>
<td className="whitespace-nowrap pl-4 text-sm font-medium text-white">
<div className="flex items-center gap-3">
<p className="w-80 truncate">{`${instanceUrl}/${short_key}`}</p>
<p className="w-80 truncate">{`${process.env.NEXT_PUBLIC_INSTANCE_URL}/${short_key}`}</p>
<a
referrerPolicy="no-referrer"
href={`${instanceUrl}/${short_key}`}
href={`${process.env.NEXT_PUBLIC_INSTANCE_URL}/${short_key}`}
target="_blank"
className="p-2 bg-white bg-opacity-10 rounded cursor-pointer"
>

View File

@ -18,9 +18,8 @@ const LoginForm = () => {
resolver: zodResolver(LoginSchema),
});
const onSubmit = async ({ masterkey, instanceUrl }: LoginType) => {
const onSubmit = async ({ masterkey }: LoginType) => {
Cookies.set('masterKey', masterkey);
Cookies.set('instanceUrl', instanceUrl);
try {
const res = await api.apiKeys.createKey();
if (res) {
@ -28,14 +27,12 @@ const LoginForm = () => {
router.push('/dashboard');
} else {
Cookies.remove('masterKey');
Cookies.remove('instanceUrl');
Cookies.remove('apiKey');
}
} catch (err) {
console.error(err);
toast.error('error');
Cookies.remove('masterKey');
Cookies.remove('instanceUrl');
Cookies.remove('apiKey');
}
};
@ -53,14 +50,6 @@ const LoginForm = () => {
type="text"
id="masterKey"
/>
<Input
{...register('instanceUrl')}
label="Instance Url"
withLabel={true}
placeholder="Instance Url"
type="text"
id="instanceUrl"
/>
<Button type="submit" className="mt-8">
Sign in
</Button>

View File

@ -2,7 +2,6 @@ import { z } from 'zod';
export const LoginSchema = z.object({
masterkey: z.string().max(256),
instanceUrl: z.string().url(),
});
export type LoginType = z.infer<typeof LoginSchema>;