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
12 changes: 7 additions & 5 deletions apps/web/pages/api/auth/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ const callback: NextApiHandler = async (req, res) => {
const redirectedFrom = req.query.redirectedFrom;

if (typeof code !== "string") {
return res.redirect(
`/login?error=${encodeURIComponent("Missing or invalid code")}`
);
const error =
typeof req.query.error_description === "string"
? req.query.error_description
: "Missing or invalid code";
return res.redirect(`/login?error=${encodeURIComponent(error)}`);
}

const supabase = createServerClientForAPI({ req, res });
Expand All @@ -25,13 +27,13 @@ const callback: NextApiHandler = async (req, res) => {
if (!data.session) {
console.error("Auth callback: No session created");
return res.redirect(
`/login?error=${encodeURIComponent("No session created")}`
`/login?error=${encodeURIComponent("No session created")}`,
);
}
} catch (err) {
console.error("Auth callback exception:", err);
return res.redirect(
`/login?error=${encodeURIComponent("Authentication failed")}`
`/login?error=${encodeURIComponent("Authentication failed")}`,
);
}

Expand Down
23 changes: 19 additions & 4 deletions apps/web/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useUserData } from "../utils/useUser";

export default function Login() {
const router = useRouter();
const { redirectedFrom } = router.query;
const { error, redirectedFrom } = router.query;

const { supabase } = useUserData();
const prefersColorScheme = usePrefersColorScheme();
Expand All @@ -47,7 +47,7 @@ export default function Login() {
const msg = error.message.toLowerCase();
if (msg.includes("signups not allowed") || msg.includes("not found")) {
notifyError(
"No account found for this email. Sign up with Google or GitHub."
"No account found for this email. New registrations are closed.",
);
} else {
notifyError(error.message);
Expand Down Expand Up @@ -108,9 +108,13 @@ export default function Login() {
</Link>

<h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900 dark:text-gray-100">
Get Started
Sign in
</h2>

<p className="mt-2 text-center text-sm text-gray-600 dark:text-gray-400">
Sign-ins are limited to existing accounts.
</p>

<p className="mt-6 text-center text-sm font-medium text-gray-600 dark:text-gray-400">
By using changes.page you agree to our{" "}
<Link href={"/terms"} className="underline">
Expand All @@ -124,6 +128,14 @@ export default function Login() {
</p>
</div>

{typeof error === "string" && (
<p className="rounded-md border border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-800 dark:bg-red-950 dark:text-red-300">
{error.toLowerCase().includes("signup")
? "New registrations are closed. Existing users can still sign in."
: error}
</p>
)}

<Auth
supabaseClient={supabase}
appearance={{
Expand Down Expand Up @@ -158,7 +170,10 @@ export default function Login() {
/>

<div className="relative my-4">
<div className="absolute inset-0 flex items-center" aria-hidden="true">
<div
className="absolute inset-0 flex items-center"
aria-hidden="true"
>
<div className="w-full border-t border-gray-300 dark:border-gray-700" />
</div>
<div className="relative flex justify-center text-sm">
Expand Down