Fixed sign in with an invite token when user is signed out
This commit is contained in:
@@ -10,6 +10,12 @@ import pathsConfig from '~/config/paths.config';
|
||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
|
||||
interface SignInPageProps {
|
||||
searchParams: {
|
||||
invite_token?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export const generateMetadata = async () => {
|
||||
const i18n = await createI18nServerInstance();
|
||||
|
||||
@@ -21,20 +27,31 @@ export const generateMetadata = async () => {
|
||||
const paths = {
|
||||
callback: pathsConfig.auth.callback,
|
||||
home: pathsConfig.app.home,
|
||||
joinTeam: pathsConfig.app.joinTeam,
|
||||
};
|
||||
|
||||
function SignInPage() {
|
||||
function SignInPage({ searchParams }: SignInPageProps) {
|
||||
const inviteToken = searchParams.invite_token;
|
||||
|
||||
const signUpPath =
|
||||
pathsConfig.auth.signUp +
|
||||
(inviteToken ? `?invite_token=${inviteToken}` : '');
|
||||
|
||||
return (
|
||||
<>
|
||||
<Heading level={4}>
|
||||
<Trans i18nKey={'auth:signInHeading'} />
|
||||
</Heading>
|
||||
|
||||
<SignInMethodsContainer paths={paths} providers={authConfig.providers} />
|
||||
<SignInMethodsContainer
|
||||
inviteToken={inviteToken}
|
||||
paths={paths}
|
||||
providers={authConfig.providers}
|
||||
/>
|
||||
|
||||
<div className={'flex justify-center'}>
|
||||
<Button asChild variant={'link'} size={'sm'}>
|
||||
<Link href={pathsConfig.auth.signUp}>
|
||||
<Link href={signUpPath}>
|
||||
<Trans i18nKey={'auth:doNotHaveAccountYet'} />
|
||||
</Link>
|
||||
</Button>
|
||||
|
||||
@@ -32,6 +32,10 @@ const paths = {
|
||||
function SignUpPage({ searchParams }: Props) {
|
||||
const inviteToken = searchParams.invite_token;
|
||||
|
||||
const signInPath =
|
||||
pathsConfig.auth.signIn +
|
||||
(inviteToken ? `?invite_token=${inviteToken}` : '');
|
||||
|
||||
return (
|
||||
<>
|
||||
<Heading level={4}>
|
||||
@@ -46,7 +50,7 @@ function SignUpPage({ searchParams }: Props) {
|
||||
|
||||
<div className={'justify-centers flex'}>
|
||||
<Button asChild variant={'link'} size={'sm'}>
|
||||
<Link href={pathsConfig.auth.signIn}>
|
||||
<Link href={signInPath}>
|
||||
<Trans i18nKey={'auth:alreadyHaveAnAccount'} />
|
||||
</Link>
|
||||
</Button>
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
"cross-env": "^7.0.3",
|
||||
"pnpm": "^9.2.0",
|
||||
"prettier": "^3.3.1",
|
||||
"turbo": "^2.0.1",
|
||||
"turbo": "2.0.2-canary.2",
|
||||
"typescript": "^5.4.5",
|
||||
"yarn": "^1.22.22"
|
||||
},
|
||||
|
||||
@@ -14,6 +14,7 @@ import { AuthProviderButton } from './auth-provider-button';
|
||||
|
||||
export function OauthProviders(props: {
|
||||
inviteToken?: string;
|
||||
shouldCreateUser: boolean;
|
||||
enabledProviders: Provider[];
|
||||
|
||||
paths: {
|
||||
@@ -85,6 +86,7 @@ export function OauthProviders(props: {
|
||||
const credentials = {
|
||||
provider,
|
||||
options: {
|
||||
shouldCreateUser: props.shouldCreateUser,
|
||||
redirectTo,
|
||||
...scopesOpts,
|
||||
},
|
||||
|
||||
@@ -13,9 +13,12 @@ import { OauthProviders } from './oauth-providers';
|
||||
import { PasswordSignInContainer } from './password-sign-in-container';
|
||||
|
||||
export function SignInMethodsContainer(props: {
|
||||
inviteToken?: string;
|
||||
|
||||
paths: {
|
||||
callback: string;
|
||||
home: string;
|
||||
joinTeam: string;
|
||||
};
|
||||
|
||||
providers: {
|
||||
@@ -32,7 +35,17 @@ export function SignInMethodsContainer(props: {
|
||||
: '';
|
||||
|
||||
const onSignIn = () => {
|
||||
router.replace(nextPath);
|
||||
if (props.inviteToken) {
|
||||
const searchParams = new URLSearchParams({
|
||||
invite_token: props.inviteToken,
|
||||
});
|
||||
|
||||
const joinTeamPath = props.paths.joinTeam + '?' + searchParams.toString();
|
||||
|
||||
router.replace(joinTeamPath);
|
||||
} else {
|
||||
router.replace(nextPath);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -42,7 +55,10 @@ export function SignInMethodsContainer(props: {
|
||||
</If>
|
||||
|
||||
<If condition={props.providers.magicLink}>
|
||||
<MagicLinkAuthContainer redirectUrl={redirectUrl} />
|
||||
<MagicLinkAuthContainer
|
||||
inviteToken={props.inviteToken}
|
||||
redirectUrl={redirectUrl}
|
||||
/>
|
||||
</If>
|
||||
|
||||
<If condition={props.providers.oAuth.length}>
|
||||
@@ -50,6 +66,8 @@ export function SignInMethodsContainer(props: {
|
||||
|
||||
<OauthProviders
|
||||
enabledProviders={props.providers.oAuth}
|
||||
inviteToken={props.inviteToken}
|
||||
shouldCreateUser={false}
|
||||
paths={{
|
||||
callback: props.paths.callback,
|
||||
returnPath: props.paths.home,
|
||||
|
||||
@@ -51,6 +51,7 @@ export function SignUpMethodsContainer(props: {
|
||||
<OauthProviders
|
||||
enabledProviders={props.providers.oAuth}
|
||||
inviteToken={props.inviteToken}
|
||||
shouldCreateUser={true}
|
||||
paths={{
|
||||
callback: props.paths.callback,
|
||||
returnPath: props.paths.appHome,
|
||||
|
||||
16906
pnpm-lock.yaml
generated
16906
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user