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