Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: onboarding redirection loop and bug fixes #3250

Merged
merged 4 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
44 changes: 25 additions & 19 deletions web/hooks/use-sign-in-redirection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,32 @@

const handleSignInRedirection = useCallback(
async (user: IUser) => {
// if the user is not onboarded, redirect them to the onboarding page
if (!user.is_onboarded) {
router.push("/onboarding");
return;
}
// if next_url is provided, redirect the user to that url
if (next_url) {
router.push(next_url.toString());
return;
}
try {
// if the user is not onboarded, redirect them to the onboarding page
if (!user.is_onboarded) {
router.push("/onboarding");
return;
}
// if next_url is provided, redirect the user to that url
if (next_url) {
router.push(next_url.toString());
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
return;
}

// Fetch the current user settings
const userSettings: IUserSettings = await fetchCurrentUserSettings();

// if the user is onboarded, fetch their last workspace details
await fetchCurrentUserSettings()
.then((userSettings: IUserSettings) => {
const workspaceSlug =
userSettings?.workspace?.last_workspace_slug || userSettings?.workspace?.fallback_workspace_slug;
if (workspaceSlug) router.push(`/${workspaceSlug}`);
else router.push("/profile");
})
.catch((err) => setError(err));
// Extract workspace details
const workspaceSlug =
userSettings?.workspace?.last_workspace_slug || userSettings?.workspace?.fallback_workspace_slug;

// Redirect based on workspace details or to profile if not available
if (workspaceSlug) router.push(`/${workspaceSlug}`);
else router.push("/profile");
} catch (error) {
console.error("Error in handleSignInRedirection:", error);
setError(error);
}
},
[fetchCurrentUserSettings, router, next_url]
);
Expand Down
12 changes: 4 additions & 8 deletions web/pages/onboarding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { Controller, useForm } from "react-hook-form";
import { useMobxStore } from "lib/mobx/store-provider";
// services
import { WorkspaceService } from "services/workspace.service";
// hooks
import useUserAuth from "hooks/use-user-auth";
// layouts
import DefaultLayout from "layouts/default-layout";
import { UserAuthWrapper } from "layouts/auth-layout";
Expand Down Expand Up @@ -45,8 +43,6 @@ const OnboardingPage: NextPageWithLayout = observer(() => {

const { setTheme } = useTheme();

const {} = useUserAuth("onboarding");

const { control, setValue } = useForm<{ full_name: string }>({
defaultValues: {
full_name: "",
Expand Down Expand Up @@ -158,8 +154,8 @@ const OnboardingPage: NextPageWithLayout = observer(() => {
currentUser?.first_name
? `${currentUser?.first_name} ${currentUser?.last_name ?? ""}`
: value.length > 0
? value
: currentUser?.email
? value
: currentUser?.email
}
src={currentUser?.avatar}
size={35}
Expand All @@ -174,8 +170,8 @@ const OnboardingPage: NextPageWithLayout = observer(() => {
{currentUser?.first_name
? `${currentUser?.first_name} ${currentUser?.last_name ?? ""}`
: value.length > 0
? value
: null}
? value
: null}
</p>
)}

Expand Down
Loading