add admin setup token i love admin setup token
This commit is contained in:
parent
660da70666
commit
ac13e77dc4
15 changed files with 136 additions and 21 deletions
|
@ -24,10 +24,11 @@ export const login = async (email: string, password: string) => {
|
|||
return response.data;
|
||||
};
|
||||
|
||||
export const register = async (email: string, password: string) => {
|
||||
export const register = async (email: string, password: string, adminToken: string) => {
|
||||
const response = await api.post<AuthResponse>('/auth/register', {
|
||||
email,
|
||||
password,
|
||||
admin_token: adminToken,
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
|
|
|
@ -20,6 +20,7 @@ import { useToast } from '@/hooks/use-toast'
|
|||
const formSchema = z.object({
|
||||
email: z.string().email('Invalid email address'),
|
||||
password: z.string().min(6, 'Password must be at least 6 characters long'),
|
||||
adminToken: z.string(),
|
||||
})
|
||||
|
||||
type FormValues = z.infer<typeof formSchema>
|
||||
|
@ -34,6 +35,7 @@ export function AuthForms() {
|
|||
defaultValues: {
|
||||
email: '',
|
||||
password: '',
|
||||
adminToken: '',
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -42,14 +44,14 @@ export function AuthForms() {
|
|||
if (activeTab === 'login') {
|
||||
await login(values.email, values.password)
|
||||
} else {
|
||||
await register(values.email, values.password)
|
||||
await register(values.email, values.password, values.adminToken)
|
||||
}
|
||||
form.reset()
|
||||
} catch (err: any) {
|
||||
toast({
|
||||
variant: 'destructive',
|
||||
title: 'Error',
|
||||
description: err.response?.data?.error || 'An error occurred',
|
||||
description: err.response?.data || 'An error occurred',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -93,6 +95,22 @@ export function AuthForms() {
|
|||
)}
|
||||
/>
|
||||
|
||||
{activeTab === 'register' && (
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="adminToken"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Admin Setup Token</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="text" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Button type="submit" className="w-full">
|
||||
{activeTab === 'login' ? 'Sign in' : 'Create account'}
|
||||
</Button>
|
||||
|
@ -102,4 +120,4 @@ export function AuthForms() {
|
|||
</Tabs>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,9 +81,11 @@ export function LinkList({ refresh = 0 }: LinkListProps) {
|
|||
}
|
||||
|
||||
const handleCopy = (shortCode: string) => {
|
||||
navigator.clipboard.writeText(`http://localhost:8080/${shortCode}`)
|
||||
// Use import.meta.env.VITE_BASE_URL or fall back to window.location.origin
|
||||
const baseUrl = import.meta.env.VITE_API_URL || window.location.origin
|
||||
navigator.clipboard.writeText(`${baseUrl}/${shortCode}`)
|
||||
toast({
|
||||
description: "Link copied to clipboard",
|
||||
description: "Link copied to clipboard",
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import * as api from '../api/client';
|
|||
interface AuthContextType {
|
||||
user: User | null;
|
||||
login: (email: string, password: string) => Promise<void>;
|
||||
register: (email: string, password: string) => Promise<void>;
|
||||
register: (email: string, password: string, adminToken: string) => Promise<void>;
|
||||
logout: () => void;
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|||
setUser(user);
|
||||
};
|
||||
|
||||
const register = async (email: string, password: string) => {
|
||||
const response = await api.register(email, password);
|
||||
const register = async (email: string, password: string, adminToken: string) => {
|
||||
const response = await api.register(email, password, adminToken);
|
||||
const { token, user } = response;
|
||||
localStorage.setItem('token', token);
|
||||
localStorage.setItem('user', JSON.stringify(user));
|
||||
|
|
|
@ -35,3 +35,9 @@ export interface SourceStats {
|
|||
source: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
export interface RegisterRequest {
|
||||
email: string;
|
||||
password: string;
|
||||
admin_token: string;
|
||||
}
|
|
@ -3,15 +3,12 @@ import react from '@vitejs/plugin-react'
|
|||
import tailwindcss from '@tailwindcss/vite'
|
||||
import path from "path"
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
react(),
|
||||
tailwindcss(),
|
||||
],
|
||||
export default defineConfig(() => ({
|
||||
plugins: [react(), tailwindcss()],
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:8080',
|
||||
target: process.env.VITE_API_URL || 'http://localhost:8080',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
|
@ -21,5 +18,4 @@ export default defineConfig({
|
|||
"@": path.resolve(__dirname, "./src"),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
}))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue