Skip to content

Commit 26fb366

Browse files
fix: address review comments
1 parent ab1405a commit 26fb366

File tree

6 files changed

+16
-51
lines changed

6 files changed

+16
-51
lines changed

AUTHENTICATION_SETUP.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ This guide will help you set up Appwrite authentication for your Practice Exams
5252

5353
1. Go to **Auth****Templates**
5454
2. Customize the email templates for:
55-
- Magic URL (email OTP)
55+
- Email OTP verification
5656
- Email verification
5757

5858
## Step 3: Environment Variables
@@ -99,7 +99,7 @@ In your Appwrite project settings, you need to configure callback URLs for OAuth
9999

100100
### Authentication Methods
101101

102-
- **Email OTP**: Magic link authentication via email
102+
- **Email OTP**: 6-digit verification code sent via email
103103
- **Google OAuth**: Sign in with Google account
104104
- **Apple OAuth**: Sign in with Apple ID
105105

app/auth/callback/page.tsx

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ function AuthCallbackContent() {
1919
const handleCallback = async () => {
2020
try {
2121
// Check if this is an OAuth callback
22-
const userId = searchParams.get("userId");
23-
const secret = searchParams.get("secret");
2422
const success = searchParams.get("success");
2523
const failure = searchParams.get("failure");
2624

@@ -40,23 +38,6 @@ function AuthCallbackContent() {
4038
return;
4139
}
4240

43-
// Handle magic link callback
44-
if (userId && secret) {
45-
const result = await AuthService.updateEmailSession(userId, secret);
46-
if (result.success) {
47-
// Refresh auth context to update authentication state
48-
await refreshUser();
49-
setStatus("success");
50-
setMessage("Email verified successfully! Redirecting...");
51-
setTimeout(() => router.push("/"), 2000);
52-
} else {
53-
setStatus("error");
54-
setMessage(result.error?.message || "Verification failed");
55-
setTimeout(() => router.push("/"), 3000);
56-
}
57-
return;
58-
}
59-
6041
// If no callback parameters, redirect to home
6142
router.push("/");
6243
} catch (error) {

components/AuthModal.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ export const AuthModal: React.FC<AuthModalProps> = ({
1515
onClose,
1616
trialExpired = false,
1717
}) => {
18-
const { signInWithEmail, verifyEmailOTP, signInWithGoogle, signInWithApple } =
19-
useAuth();
18+
const {
19+
sendEmailOTP,
20+
verifyOTPAndSignIn,
21+
signInWithGoogle,
22+
signInWithApple,
23+
} = useAuth();
2024
const [email, setEmail] = useState("");
2125
const [otp, setOtp] = useState("");
2226
const [userId, setUserId] = useState<string | null>(null);
@@ -54,7 +58,7 @@ export const AuthModal: React.FC<AuthModalProps> = ({
5458
setMessage("");
5559

5660
try {
57-
const result = await signInWithEmail(email.trim());
61+
const result = await sendEmailOTP(email.trim());
5862
if (result.success && result.userId) {
5963
setUserId(result.userId);
6064
// Save last used method
@@ -81,7 +85,7 @@ export const AuthModal: React.FC<AuthModalProps> = ({
8185
setMessage("");
8286

8387
try {
84-
const result = await verifyEmailOTP(userId, otp.trim());
88+
const result = await verifyOTPAndSignIn(userId, otp.trim());
8589
if (result.success) {
8690
setIsVerifying(false);
8791
setIsRedirecting(true);

contexts/AuthContext.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ interface AuthContextType {
77
user: AuthUser | null;
88
isLoading: boolean;
99
isAuthenticated: boolean;
10-
signInWithEmail: (
10+
sendEmailOTP: (
1111
email: string,
1212
) => Promise<{ success: boolean; error?: string; userId?: string }>;
13-
verifyEmailOTP: (
13+
verifyOTPAndSignIn: (
1414
userId: string,
1515
otp: string,
1616
) => Promise<{ success: boolean; error?: string }>;
@@ -57,7 +57,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
5757
}
5858
};
5959

60-
const signInWithEmail = async (email: string) => {
60+
const sendEmailOTP = async (email: string) => {
6161
try {
6262
const result = await AuthService.createEmailOTPSession(email);
6363
if (result.success) {
@@ -70,7 +70,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
7070
}
7171
};
7272

73-
const verifyEmailOTP = async (userId: string, otp: string) => {
73+
const verifyOTPAndSignIn = async (userId: string, otp: string) => {
7474
try {
7575
const result = await AuthService.verifyEmailOTP(userId, otp);
7676
if (result.success) {
@@ -127,8 +127,8 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
127127
user,
128128
isLoading,
129129
isAuthenticated,
130-
signInWithEmail,
131-
verifyEmailOTP,
130+
sendEmailOTP,
131+
verifyOTPAndSignIn,
132132
signInWithGoogle,
133133
signInWithApple,
134134
signOut,

hooks/useSecureTrial.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export const useSecureTrial = () => {
5959
const getUserIP = async (): Promise<string> => {
6060
// Try multiple IP services for better reliability
6161
const ipServices = [
62-
"/api/get-ip", // Local API route first
6362
"https://api.ipify.org?format=json",
6463
"https://ipapi.co/json/",
6564
"https://api.ip.sb/geoip",

lib/appwrite/auth.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,6 @@ export class AuthService {
6464
}
6565
}
6666

67-
static async updateEmailSession(
68-
userId: string,
69-
secret: string,
70-
): Promise<{ success: boolean; error?: AuthError }> {
71-
try {
72-
this.checkAppwriteAvailable();
73-
await account!.updateMagicURLSession(userId, secret);
74-
return { success: true };
75-
} catch (error: any) {
76-
return {
77-
success: false,
78-
error: {
79-
message: error.message || "Failed to verify OTP",
80-
code: error.code,
81-
},
82-
};
83-
}
84-
}
85-
8667
// Google OAuth
8768
static async createGoogleSession(): Promise<{
8869
success: boolean;

0 commit comments

Comments
 (0)