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

V2 #236

Merged
merged 1 commit into from
Feb 23, 2024
Merged

V2 #236

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions v2/src/actions/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,19 @@ export const ForgetPassword = async (values: z.infer<typeof ForgetPasswordSchema
}
}
};

export const CheckAuth = () => {
const authToken = cookies()?.get('access_token')?.value;

if (!authToken) {
return {
status: 401, // Change status to 401 for unauthorized
error: 'Unauthorized. Missing access token.',
};
}

return {
status: 200,
succes: 'authorized',
};
};
12 changes: 0 additions & 12 deletions v2/src/app/(home)/layout.tsx

This file was deleted.

18 changes: 18 additions & 0 deletions v2/src/app/(home)/template.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use client';

import React from 'react';
import HomeFooter from '@/components/home/Footer';
import NavBar from '@/components/home/NavBar';
import NavBarAuthenticated from '@/components/Header/NavBarAuthenticated';
import { CheckAuthFromLocalStorage } from '@/helpers/auth';

export default function GeneralTemplate({ children }: { children: React.ReactNode }) {
const Authenticated = CheckAuthFromLocalStorage();
return (
<>
{Authenticated ? <NavBarAuthenticated /> : <NavBar />}
{children}
{!Authenticated && <HomeFooter />}
</>
);
}
3 changes: 2 additions & 1 deletion v2/src/components/Forms/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ const Login = () => {
setError(data?.error);
if (data?.success) {
console.log('User came from signIn');
localStorage.setItem('authenticated', 'true');
setTimeout(() => {
setSuccess('Redirecting....');
}, 1000);
setTimeout(() => {
router.push(DEFAULT_LOGIN_REDIRECT);
router.push('/auth/sign-up');
}, 2000);
}
});
Expand Down
7 changes: 7 additions & 0 deletions v2/src/components/Header/NavBarAuthenticated.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

const NavBarAuthenticated = () => {
return <div>NavBarAuthenticated</div>;
};

export default NavBarAuthenticated;
2 changes: 1 addition & 1 deletion v2/src/components/ui/FormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const FormInput = React.forwardRef<HTMLInputElement, InputProps>(({ className, t
<input
type={type}
className={cn(
'flex h-10 w-full rounded-md border dark:text-gray-200 dark:border-dark-two bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-transparent',
'flex h-10 w-full rounded-md border dark:text-white-100 dark:border-dark-two bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-transparent',
className,
)}
ref={ref}
Expand Down
6 changes: 6 additions & 0 deletions v2/src/helpers/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function CheckAuthFromLocalStorage(): string | null {
if (typeof window !== 'undefined') {
return localStorage.getItem('authenticated') as string | null;
}
return null;
}
145 changes: 145 additions & 0 deletions v2/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,148 @@ export interface AuthContextProps {
export interface UserDetails {
id: string;
}

export interface EventDataProps {
title: string;
description: string;
imageURL: string;
startDate: Date;
endDate: Date;
time: string;
location: string;
capacity: string;
entranceFee: string;
eventType: string;
organizerID: string;
categoryName: string;
startTime: string;
endTime: string;
virtualLocationLink?: string;
locationType: 'Physical' | 'Virtual';
ticketType: 'Free' | 'Premium';
}

export interface UploadResponse {
timestamp: string;
success: boolean;
status: number;
data: {
imageURL: string;
};
message: string;
}

export interface UploadParams {
file: File;
}

export interface EventPayload {
title: string;
description: string;
imageURL: string;
startDate: string;
endDate: string;
locationType: 'Physical' | 'Virtual';
location?: string;
virtualLocationLink?: string;
time?: string;
capacity: number;
eventType: string;
organizerID: string;
categoryName: string;
ticketType: string;
ticketPrice: number;
entranceFee?: number;
ticketID?: string;
}

export interface EventParticipant {
userID: string;
email: string;
profileImage: string | null;
firstName: string;
lastName: string;
}

export interface EventsProps {
eventID: string;
title: string;
description: string;
imageURL: string;
startDate: string;
endDate: string;
time: string;
location: string;
capacity: number;
entranceFee: number;
eventType: string;
organizerID: string;
categoryCategoryID: string;
participants: EventParticipant[];
tickets: {
ticketID: string;
ticketPrice: number;
ticketType: string;
}[];
}

export interface UserProfile2 {
userID?: string;
email?: string;
bio?: string;

profileImage?: string | Blob | File;
displayName?: string;
firstName?: string;
lastName?: string;
slug?: string;
role?: string;
location?: string;
}

export interface UserProfile {
userID: string;
email: string;
bio: string;
coverImage?: string;

profileImage: string;
displayName: string;
firstName: string;
lastName: string;
slug: string;
role: string;
location: string;
}
export interface socialLinks {
facebookURL?: string;
instagramURL?: string;
twitterURL?: string;
websiteURL?: string;
}

export type participantType = {
userID: string;
email: string;
profileImage: string | null;
firstName: string;
lastName: string;
};

export type eventType = {
eventID?: string;
title?: string;
description?: string;
imageURL?: string;
startDate: string;
endDate?: string;
time?: string;
location?: string;
locationType: string;
capacity?: number;
entranceFee?: number;
eventType?: string;
organizerID: string;
categoryCategoryID?: string;
participants?: participantType[];
};
Loading