Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -4,11 +4,16 @@ import Spinner from "@unsend/ui/src/spinner";
|
||||
import { getServerAuthSession } from "~/server/auth";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function CreateTeam() {
|
||||
export default async function CreateTeam({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: { inviteId?: string };
|
||||
}) {
|
||||
const session = await getServerAuthSession();
|
||||
|
||||
if (!session) {
|
||||
redirect("/login");
|
||||
const inviteId = searchParams?.inviteId;
|
||||
redirect(`/login${inviteId ? `?inviteId=${inviteId}` : ""}`);
|
||||
}
|
||||
|
||||
return (
|
||||
|
@@ -26,6 +26,7 @@ import { BuiltInProviderType } from "next-auth/providers/index";
|
||||
import Spinner from "@unsend/ui/src/spinner";
|
||||
import Link from "next/link";
|
||||
import { useTheme } from "@unsend/ui";
|
||||
import { useSearchParams as useNextSearchParams } from "next/navigation";
|
||||
|
||||
const emailSchema = z.object({
|
||||
email: z
|
||||
@@ -93,9 +94,10 @@ export default function LoginPage({
|
||||
const email = emailForm.getValues().email;
|
||||
console.log("email", email);
|
||||
|
||||
const finalCallbackUrl = inviteId ? `/join-team?inviteId=${inviteId}` : `${callbackUrl}/dashboard`;
|
||||
window.location.href = `/api/auth/callback/email?email=${encodeURIComponent(
|
||||
email.toLowerCase()
|
||||
)}&token=${values.otp.toLowerCase()}${callbackUrl ? `&callbackUrl=${callbackUrl}/dashboard` : ""}`;
|
||||
)}&token=${values.otp.toLowerCase()}&callbackUrl=${encodeURIComponent(finalCallbackUrl)}`;
|
||||
}
|
||||
|
||||
const emailProvider = providers?.find(
|
||||
@@ -105,9 +107,13 @@ export default function LoginPage({
|
||||
const [submittedProvider, setSubmittedProvider] =
|
||||
useState<LiteralUnion<BuiltInProviderType> | null>(null);
|
||||
|
||||
const searchParams = useNextSearchParams();
|
||||
const inviteId = searchParams.get("inviteId");
|
||||
|
||||
const handleSubmit = (provider: LiteralUnion<BuiltInProviderType>) => {
|
||||
setSubmittedProvider(provider);
|
||||
signIn(provider);
|
||||
const callbackUrl = inviteId ? `/join-team?inviteId=${inviteId}` : "/dashboard";
|
||||
signIn(provider, { callbackUrl });
|
||||
};
|
||||
|
||||
const { resolvedTheme } = useTheme();
|
||||
|
@@ -53,6 +53,11 @@ function getProviders() {
|
||||
clientId: env.GITHUB_ID,
|
||||
clientSecret: env.GITHUB_SECRET,
|
||||
allowDangerousEmailAccountLinking: true,
|
||||
authorization: {
|
||||
params: {
|
||||
scope: 'read:user user:email'
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user