Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = [
]

[workspace.dependencies]
soroban-sdk = "21.0.0"
soroban-sdk = "22"

[profile.release]
opt-level = "z"
Expand Down
2 changes: 1 addition & 1 deletion app/auth/verify-otp/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default function VerifyOTP() {

if (response.ok) {
// const data = await response.json()
router.push("/projects/12");
router.push("/dashboard");
} else {
const data = await response.json();
setError(data.message || "Invalid OTP. Please try again.");
Expand Down
184 changes: 98 additions & 86 deletions components/signin-form.tsx
Original file line number Diff line number Diff line change
@@ -1,98 +1,110 @@
"use client"
"use client";

import { useState } from "react"
import { signIn } from "next-auth/react"
import { useRouter } from "next/navigation"
import { useState } from "react";
import { signIn } from "next-auth/react";
import { useRouter } from "next/navigation";
import { Button } from "./ui/button";

export default function SignInForm() {
const [email, setEmail] = useState("")
const [password, setPassword] = useState("")
const [error, setError] = useState("")
const router = useRouter()
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState("");
const [isLoading, setIsLoading] = useState(false);
const router = useRouter();

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
setError("")
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError("");
setIsLoading(true);

const result = await signIn("credentials", {
redirect: false,
email,
password,
})
const result = await signIn("credentials", {
redirect: false,
email,
password,
});

if (result?.error === "UNVERIFIED_EMAIL") {
setError("Your email is not verified. Sending verification code...")
if (result?.error === "UNVERIFIED_EMAIL") {
setError("Your email is not verified. Sending verification code...");

try {
const otpResponse = await fetch("/api/auth/resend-otp", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email }),
})
try {
const otpResponse = await fetch("/api/auth/resend-otp", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email }),
});

if (!otpResponse.ok) {
const data = await otpResponse.json()
setError(data.message || "Failed to send verification code")
return
}
router.push(`/auth/verify-otp?email=${encodeURIComponent(email)}`)
} catch (err) {
setError(`Failed to send verification code: ${err instanceof Error ? err.message : String(err)}`)
}
} else if (result?.error) {
setError(result.error)
} else {
router.push("/projects/12")
}
}
if (!otpResponse.ok) {
const data = await otpResponse.json();
setError(data.message || "Failed to send verification code");
return;
}
router.push(`/auth/verify-otp?email=${encodeURIComponent(email)}`);
} catch (err) {
setError(
`Failed to send verification code: ${
err instanceof Error ? err.message : String(err)
}`,
);
} finally {
setIsLoading(false);
}
} else if (result?.error) {
setError(result.error);
setIsLoading(false);
} else {
setIsLoading(false);
router.push("/dashboard");
}
};

return (
<form onSubmit={handleSubmit} className="mt-2 space-y-6">
<div className="rounded-md shadow-sm -space-y-px">
<div>
<label htmlFor="email-address" className="sr-only">
Email address
</label>
<input
id="email-address"
name="email"
type="email"
autoComplete="email"
required
className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
placeholder="Email address"
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
</div>
<div>
<label htmlFor="password" className="sr-only">
Password
</label>
<input
id="password"
name="password"
type="password"
autoComplete="current-password"
required
className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-b-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
placeholder="Password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
</div>
</div>
return (
<form onSubmit={handleSubmit} className="mt-2 space-y-6">
<div className="rounded-md shadow-sm -space-y-px">
<div>
<label htmlFor="email-address" className="sr-only">
Email address
</label>
<input
id="email-address"
name="email"
type="email"
autoComplete="email"
required
className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
placeholder="Email address"
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
</div>
<div>
<label htmlFor="password" className="sr-only">
Password
</label>
<input
id="password"
name="password"
type="password"
autoComplete="current-password"
required
className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-b-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
placeholder="Password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
</div>
</div>

{error && <p className="text-red-500 text-xs italic">{error}</p>}
{error && <p className="text-red-500 text-xs italic">{error}</p>}

<div>
<button
type="submit"
className="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-primary hover:bg-primary/85 focus:outline-none"
>
Sign in
</button>
</div>
</form>
)
<div>
<Button
disabled={isLoading}
type="submit"
className="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-primary hover:bg-primary/85 focus:outline-none"
>
{isLoading ? "Signing in..." : "Sign in"}
</Button>
</div>
</form>
);
}
2 changes: 1 addition & 1 deletion lib/auth.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const authOptions: NextAuthOptions = {

callbacks: {
async redirect({ url, baseUrl }) {
return url.startsWith(baseUrl) ? url : `${baseUrl}/projects/12`;
return url.startsWith(baseUrl) ? url : `${baseUrl}/dashboard`;
},
async jwt({ token, user }): Promise<CustomToken> {
if (user) {
Expand Down