Skip to content

Commit 0a2382f

Browse files
author
MStarRobotics
committed
fix: Resolve security vulnerabilities and linting errors
1 parent a564c66 commit 0a2382f

File tree

4 files changed

+86
-76
lines changed

4 files changed

+86
-76
lines changed

components/auth/EmailLinkAuthExample.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ export function EmailLinkAuthExample() {
2323
// Check if current URL is a sign-in link
2424
if (isEmailSignInLink()) {
2525
setIsCompletingSignIn(true);
26-
handleCompleteSignIn();
26+
void handleCompleteSignIn();
2727
}
28+
// eslint-disable-next-line react-hooks/exhaustive-deps
2829
}, []);
2930

3031
const handleSendLink = async () => {
@@ -43,7 +44,7 @@ export function EmailLinkAuthExample() {
4344
};
4445

4546
await sendEmailSignInLink(email, actionCodeSettings);
46-
47+
4748
setStatus(
4849
'Sign-in link sent! Check your email and click the link to sign in. ' +
4950
'The link will work on any device.'
@@ -60,13 +61,13 @@ export function EmailLinkAuthExample() {
6061

6162
try {
6263
const result = await completeEmailSignIn(providedEmail || email);
63-
64+
6465
setStatus(`Successfully signed in as ${result.user.email}`);
6566
// Handle successful sign-in (e.g., redirect to dashboard)
66-
67+
6768
} catch (err) {
6869
const errorMessage = err instanceof Error ? err.message : 'Failed to complete sign-in';
69-
70+
7071
// If email is missing, prompt user to enter it
7172
if (errorMessage.includes('Email address is required')) {
7273
setError('Please enter your email to complete sign-in');
@@ -95,14 +96,14 @@ export function EmailLinkAuthExample() {
9596
<input
9697
type="email"
9798
value={email}
98-
onChange={(e) => setEmail(e.target.value)}
99+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setEmail(e.target.value)}
99100
placeholder="you@example.com"
100101
className="w-full px-3 py-2 border rounded focus:ring-2 focus:ring-blue-500"
101102
/>
102103
</div>
103104

104105
<button
105-
onClick={() => handleCompleteSignIn(email)}
106+
onClick={() => void handleCompleteSignIn()}
106107
disabled={!email}
107108
className="w-full bg-blue-600 text-white py-2 rounded hover:bg-blue-700 disabled:opacity-50"
108109
>
@@ -137,7 +138,7 @@ export function EmailLinkAuthExample() {
137138
<input
138139
type="email"
139140
value={email}
140-
onChange={(e) => setEmail(e.target.value)}
141+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setEmail(e.target.value)}
141142
placeholder="you@example.com"
142143
className="w-full px-3 py-2 border rounded focus:ring-2 focus:ring-blue-500"
143144
/>
@@ -147,7 +148,7 @@ export function EmailLinkAuthExample() {
147148
</div>
148149

149150
<button
150-
onClick={handleSendLink}
151+
onClick={() => void handleSendLink()}
151152
disabled={!email}
152153
className="w-full bg-blue-600 text-white py-2 rounded hover:bg-blue-700 disabled:opacity-50"
153154
>

components/auth/PhoneAuthExample.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ export function PhoneAuthExample() {
2626
try {
2727
// Create reCAPTCHA verifier (visible widget for better UX)
2828
const verifier = ensurePhoneRecaptcha('recaptcha-container', 'normal');
29-
29+
3030
setStatus('Requesting SMS code...');
31-
31+
3232
// Request SMS code
3333
const confirmationResult = await signInWithPhone(phoneNumber, verifier);
34-
34+
3535
setConfirmation(confirmationResult);
3636
setStatus('SMS code sent! Check your phone.');
3737
} catch (err) {
@@ -72,7 +72,7 @@ export function PhoneAuthExample() {
7272
<input
7373
type="tel"
7474
value={phoneNumber}
75-
onChange={(e) => setPhoneNumber(e.target.value)}
75+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setPhoneNumber(e.target.value)}
7676
placeholder="+1 234 567 8900"
7777
className="w-full px-3 py-2 border rounded focus:ring-2 focus:ring-blue-500"
7878
/>
@@ -85,7 +85,7 @@ export function PhoneAuthExample() {
8585
<div id="recaptcha-container" className="flex justify-center"></div>
8686

8787
<button
88-
onClick={handleSendCode}
88+
onClick={() => void handleSendCode()}
8989
disabled={!phoneNumber}
9090
className="w-full bg-blue-600 text-white py-2 rounded hover:bg-blue-700 disabled:opacity-50"
9191
>
@@ -101,15 +101,15 @@ export function PhoneAuthExample() {
101101
<input
102102
type="text"
103103
value={verificationCode}
104-
onChange={(e) => setVerificationCode(e.target.value)}
104+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setVerificationCode(e.target.value)}
105105
placeholder="123456"
106106
maxLength={6}
107107
className="w-full px-3 py-2 border rounded focus:ring-2 focus:ring-blue-500"
108108
/>
109109
</div>
110110

111111
<button
112-
onClick={handleVerifyCode}
112+
onClick={() => void handleVerifyCode()}
113113
disabled={verificationCode.length !== 6}
114114
className="w-full bg-green-600 text-white py-2 rounded hover:bg-green-700 disabled:opacity-50"
115115
>

package-lock.json

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

services/firebaseClient.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import {
1616
type Auth,
1717
type User,
1818
type UserCredential,
19+
sendSignInLinkToEmail,
20+
isSignInWithEmailLink,
21+
signInWithEmailLink,
22+
type ActionCodeSettings,
1923
} from 'firebase/auth';
2024

2125
let firebaseApp: FirebaseApp | null | undefined;
@@ -180,3 +184,27 @@ export const firebaseSignOut = async (): Promise<void> => {
180184
};
181185

182186
export const isFirebaseReady = (): boolean => Boolean(getFirebaseAuthInstance());
187+
188+
export const sendEmailSignInLink = async (email: string, actionCodeSettings: ActionCodeSettings): Promise<void> => {
189+
const auth = getFirebaseAuthInstance();
190+
if (!auth) {
191+
throw new Error('Firebase is not configured. Set VITE_FIREBASE_* environment variables.');
192+
}
193+
return sendSignInLinkToEmail(auth, email, actionCodeSettings);
194+
};
195+
196+
export const isEmailSignInLink = (url?: string): boolean => {
197+
const auth = getFirebaseAuthInstance();
198+
if (!auth) {
199+
return false;
200+
}
201+
return isSignInWithEmailLink(auth, url || window.location.href);
202+
};
203+
204+
export const completeEmailSignIn = async (email: string, url?: string): Promise<UserCredential> => {
205+
const auth = getFirebaseAuthInstance();
206+
if (!auth) {
207+
throw new Error('Firebase is not configured. Set VITE_FIREBASE_* environment variables.');
208+
}
209+
return signInWithEmailLink(auth, email, url || window.location.href);
210+
};

0 commit comments

Comments
 (0)