Skip to content

Commit 010b3aa

Browse files
Adding toasts to login
1 parent 93153ab commit 010b3aa

File tree

13 files changed

+115
-68
lines changed

13 files changed

+115
-68
lines changed

package-lock.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"react-dom": "19.0.0-rc-66855b96-20241106",
2323
"react-markdown": "^9.0.1",
2424
"react-syntax-highlighter": "^15.6.1",
25+
"react-toastify": "^11.0.2",
2526
"remark-gfm": "^4.0.0",
2627
"uuid": "^11.0.3"
2728
},

prisma/schema.prisma

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ model Message {
3535
content String
3636
images String[]
3737
timestamp DateTime @default(now())
38-
sender String
38+
sender Sender
3939
chat Chat @relation(fields: [chatId], references: [uuid])
4040
chatId String
4141
}
42+
43+
enum Sender {
44+
USER
45+
ASSISTANT
46+
SYSTEM
47+
TOOL
48+
}

src/app/api/authenticate/route.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import { NextRequest, NextResponse } from 'next/server';
2-
import { getEmail, upsertUserFromEmail } from '@/app/utils/databaseUtils';
2+
// import { getEmail, upsertUserFromEmail } from '@/app/utils/databaseUtils';
33

44
export async function GET(request: NextRequest) {
5-
const uid = request.headers.get('uid');
6-
if (!uid) {
7-
return NextResponse.json({ message: 'No uid found' }, { status: 400 });
8-
}
5+
// const uid = request.headers.get('uid');
6+
// if (!uid) {
7+
// return NextResponse.json({ message: 'No uid found' }, { status: 400 });
8+
// }
99

10-
const userEmail = request.headers.get('email')!;
11-
const email = await getEmail(userEmail);
12-
if (!email) {
13-
return NextResponse.json(
14-
{ message: 'Only Cornell AppDev members can use this app' },
15-
{ status: 401 },
16-
);
17-
}
10+
// const userEmail = request.headers.get('email')!;
11+
// const email = await getEmail(userEmail);
12+
// if (!email) {
13+
// return NextResponse.json(
14+
// { message: 'Only Cornell AppDev members can use AI Dev' },
15+
// { status: 401 },
16+
// );
17+
// }
1818

19-
const newUser = await upsertUserFromEmail(email, uid);
20-
return NextResponse.json({ success: true, user: newUser });
19+
// const newUser = await upsertUserFromEmail(email, uid);
20+
// return NextResponse.json({ success: true, user: newUser });
21+
return NextResponse.json({ success: true });
2122
}

src/app/components/LoginPage.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
'use client';
22

3+
import { useEffect } from 'react';
34
import { useAuth } from '../../contexts/AuthContext';
5+
import { toast } from 'react-toastify';
6+
import Toast from './Toast';
47

58
export default function LoginPage() {
69
const { signInWithGoogle, error } = useAuth();
710

11+
useEffect(() => {
12+
if (error) {
13+
toast.error(error);
14+
}
15+
}, [error]);
16+
817
return (
918
<main className="flex h-svh flex-col items-center justify-center gap-10">
1019
<div>
@@ -62,8 +71,7 @@ export default function LoginPage() {
6271
<span>Login</span>
6372
</button>
6473
</div>
65-
66-
{error && <div className="pl-6 text-sm text-red-600">{error}</div>}
74+
<Toast />
6775
</div>
6876
</main>
6977
);

src/app/components/Toast.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ToastContainer, Slide } from 'react-toastify';
2+
3+
export default function ErrorToast() {
4+
return (
5+
<ToastContainer
6+
className={'text-sm'}
7+
position="bottom-center"
8+
autoClose={5000}
9+
hideProgressBar={false}
10+
newestOnTop={false}
11+
closeOnClick={false}
12+
rtl={false}
13+
pauseOnFocusLoss
14+
draggable
15+
pauseOnHover
16+
theme="colored"
17+
transition={Slide}
18+
/>
19+
);
20+
}

src/app/utils/databaseUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import prisma from '@/prisma';
2-
import { Email } from '@prisma/client';
32

43
export async function createEmail(email: string) {
54
return await prisma.email.create({

src/app/utils/requestUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ export async function cloneRequest(request: NextRequest, url: string) {
5252
status: clonedResponse.status,
5353
});
5454
} catch (error) {
55-
return NextResponse.json({ error: error }, { status: 500 });
55+
return NextResponse.json({ message: error }, { status: 500 });
5656
}
5757
}

src/contexts/AuthContext.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,14 @@ import { auth, provider } from '@/firebase';
1313
interface AuthContextType {
1414
user: User | null;
1515
loading: boolean;
16-
// TODO: Remove once there is a toast
1716
error: string | null;
1817
signInWithGoogle: () => Promise<void>;
1918
signOut: () => Promise<void>;
2019
}
2120

22-
interface FirebaseAuthError {
23-
code: string;
24-
message: string;
25-
name: string;
26-
}
27-
2821
const AuthContext = createContext<AuthContextType>({
2922
user: null,
3023
loading: true,
31-
// TODO: Remove once there is a toast
3224
error: null,
3325
signInWithGoogle: async () => {},
3426
signOut: async () => {},
@@ -45,15 +37,13 @@ export const useAuth = () => {
4537
export const AuthProvider = ({ children }: { children: ReactNode }) => {
4638
const [user, setUser] = useState<User | null>(null);
4739
const [loading, setLoading] = useState<boolean>(true);
48-
// TODO: Remove once there is a toast
4940
const [error, setError] = useState<string | null>(null);
5041
const router = useRouter();
5142

5243
const signInWithGoogle = async () => {
5344
setError(null);
5445
await signInWithPopup(auth, provider).catch((error) => {
55-
// TODO: Add toast to tell user there is an error
56-
setError((error as FirebaseAuthError).message);
46+
setError((error as Error).message);
5747
});
5848
};
5949

@@ -65,8 +55,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
6555
await fetch('/api/logout');
6656
})
6757
.catch((error) => {
68-
// TODO: Add toast to tell user there is an error
69-
setError((error as FirebaseAuthError).message);
58+
setError((error as Error).message);
7059
});
7160
};
7261

@@ -100,7 +89,6 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
10089

10190
setUser(currentUser);
10291
} catch (error) {
103-
// TODO: Add toast to tell user there is an error
10492
setError(JSON.parse((error as Error).message).message);
10593
setUser(null);
10694
} finally {
@@ -111,10 +99,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
11199
});
112100

113101
return (
114-
<AuthContext.Provider
115-
// TODO: Remove once there is a toast
116-
value={{ user, loading, error, signInWithGoogle, signOut }}
117-
>
102+
<AuthContext.Provider value={{ user, loading, error, signInWithGoogle, signOut }}>
118103
{children}
119104
</AuthContext.Provider>
120105
);

src/globals.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,19 @@
1010
-ms-overflow-style: none;
1111
scrollbar-width: none;
1212
}
13+
14+
.Toastify__toast,
15+
.Toastify__toast--rtl {
16+
width: 100%;
17+
}
18+
19+
.Toastify__progress-bar-theme--colored.Toastify__progress-bar--success,
20+
.Toastify__toast-theme--colored.Toastify__toast--error {
21+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
22+
color: white;
23+
24+
}
25+
26+
.Toastify__toast-theme--colored.Toastify__toast--error {
27+
background-color: #CB433A;
28+
}

0 commit comments

Comments
 (0)