Fix/sso username (#1897)
* username slug should be lowercase * if logging in via a non-CAL identity provider then show username during onboarding * type fix Co-authored-by: Bailey Pumfleet <pumfleet@hey.com>
This commit is contained in:
parent
0b4f771462
commit
5b66c1f986
2 changed files with 13 additions and 6 deletions
|
@ -14,6 +14,8 @@ import slugify from "@lib/slugify";
|
||||||
|
|
||||||
import { GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, IS_GOOGLE_LOGIN_ENABLED } from "@server/lib/constants";
|
import { GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, IS_GOOGLE_LOGIN_ENABLED } from "@server/lib/constants";
|
||||||
|
|
||||||
|
const usernameSlug = (username: string) => slugify(username) + "-" + randomString(6).toLowerCase();
|
||||||
|
|
||||||
const providers: Provider[] = [
|
const providers: Provider[] = [
|
||||||
CredentialsProvider({
|
CredentialsProvider({
|
||||||
id: "credentials",
|
id: "credentials",
|
||||||
|
@ -310,7 +312,7 @@ export default NextAuth({
|
||||||
data: {
|
data: {
|
||||||
// Slugify the incoming name and append a few random characters to
|
// Slugify the incoming name and append a few random characters to
|
||||||
// prevent conflicts for users with the same name.
|
// prevent conflicts for users with the same name.
|
||||||
username: slugify(user.name) + "-" + randomString(6),
|
username: usernameSlug(user.name),
|
||||||
emailVerified: new Date(Date.now()),
|
emailVerified: new Date(Date.now()),
|
||||||
name: user.name,
|
name: user.name,
|
||||||
identityProvider: idP,
|
identityProvider: idP,
|
||||||
|
@ -332,7 +334,7 @@ export default NextAuth({
|
||||||
data: {
|
data: {
|
||||||
// Slugify the incoming name and append a few random characters to
|
// Slugify the incoming name and append a few random characters to
|
||||||
// prevent conflicts for users with the same name.
|
// prevent conflicts for users with the same name.
|
||||||
username: slugify(user.name) + "-" + randomString(6),
|
username: usernameSlug(user.name),
|
||||||
emailVerified: new Date(Date.now()),
|
emailVerified: new Date(Date.now()),
|
||||||
name: user.name,
|
name: user.name,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { ArrowRightIcon } from "@heroicons/react/outline";
|
import { ArrowRightIcon } from "@heroicons/react/outline";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma, IdentityProvider } from "@prisma/client";
|
||||||
import classnames from "classnames";
|
import classnames from "classnames";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import localizedFormat from "dayjs/plugin/localizedFormat";
|
import localizedFormat from "dayjs/plugin/localizedFormat";
|
||||||
|
@ -162,7 +162,11 @@ export default function Onboarding(props: inferSSRProps<typeof getServerSideProp
|
||||||
const [currentStep, setCurrentStep] = useState(0);
|
const [currentStep, setCurrentStep] = useState(0);
|
||||||
const detectStep = () => {
|
const detectStep = () => {
|
||||||
let step = 0;
|
let step = 0;
|
||||||
const hasSetUserNameOrTimeZone = props.user?.name && props.user?.timeZone && !props.usernameParam;
|
const hasSetUserNameOrTimeZone =
|
||||||
|
props.user?.name &&
|
||||||
|
props.user?.timeZone &&
|
||||||
|
!props.usernameParam &&
|
||||||
|
props.user?.identityProvider === IdentityProvider.CAL;
|
||||||
if (hasSetUserNameOrTimeZone) {
|
if (hasSetUserNameOrTimeZone) {
|
||||||
step = 1;
|
step = 1;
|
||||||
}
|
}
|
||||||
|
@ -348,7 +352,7 @@ export default function Onboarding(props: inferSSRProps<typeof getServerSideProp
|
||||||
</div>
|
</div>
|
||||||
<form className="sm:mx-auto sm:w-full">
|
<form className="sm:mx-auto sm:w-full">
|
||||||
<section className="space-y-8">
|
<section className="space-y-8">
|
||||||
{props.usernameParam && (
|
{(props.usernameParam || props.user?.identityProvider !== IdentityProvider.CAL) && (
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label htmlFor="name" className="block text-sm font-medium text-gray-700">
|
<label htmlFor="name" className="block text-sm font-medium text-gray-700">
|
||||||
{t("username")}
|
{t("username")}
|
||||||
|
@ -360,7 +364,7 @@ export default function Onboarding(props: inferSSRProps<typeof getServerSideProp
|
||||||
id="username"
|
id="username"
|
||||||
data-testid="username"
|
data-testid="username"
|
||||||
placeholder={t("username")}
|
placeholder={t("username")}
|
||||||
defaultValue={props.usernameParam ?? ""}
|
defaultValue={props.usernameParam ? props.usernameParam : props.user?.username ?? ""}
|
||||||
required
|
required
|
||||||
className="mt-1 block w-full rounded-sm border border-gray-300 px-3 py-2 shadow-sm focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
|
className="mt-1 block w-full rounded-sm border border-gray-300 px-3 py-2 shadow-sm focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
|
||||||
/>
|
/>
|
||||||
|
@ -666,6 +670,7 @@ export async function getServerSideProps(context: NextPageContext) {
|
||||||
bio: true,
|
bio: true,
|
||||||
avatar: true,
|
avatar: true,
|
||||||
timeZone: true,
|
timeZone: true,
|
||||||
|
identityProvider: true,
|
||||||
completedOnboarding: true,
|
completedOnboarding: true,
|
||||||
selectedCalendars: {
|
selectedCalendars: {
|
||||||
select: {
|
select: {
|
||||||
|
|
Loading…
Reference in a new issue