Skip to content

Commit

Permalink
Merge pull request #44 from diggerhq/fix/login-cache-org-cookie
Browse files Browse the repository at this point in the history
Store orgId after onboarding in a cookie
  • Loading branch information
ZIJ authored Sep 13, 2024
2 parents 486ac33 + 702b1f1 commit 04acf2e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"hastscript": "^9.0.0",
"html2canvas": "^1.4.1",
"inbucket-js-client": "^1.0.1",
"js-cookie": "^3.0.5",
"jsonwebtoken": "^9.0.2",
"jspdf": "^2.5.1",
"lodash": "^4.17.21",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export const dynamic = 'force-dynamic';

export async function GET(req: NextRequest) {
try {
const initialOrgId = req.cookies.get('organization')?.value;
if (initialOrgId) {
console.log('Initial org id from cookies:', initialOrgId);
return NextResponse.redirect(new URL(`/org/${initialOrgId}`, req.url));
}
const initialOrganization = await getInitialOrganizationToRedirectTo();
if (initialOrganization.status === 'error') {
return NextResponse.redirect(toSiteURL('/500'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import { generateSlug } from "@/lib/utils";
import { CreateOrganizationSchema, createOrganizationSchema } from "@/utils/zod-schemas/organization";
import { zodResolver } from "@hookform/resolvers/zod";
import { useMutation } from "@tanstack/react-query";
import Cookies from 'js-cookie';
import { useForm } from "react-hook-form";




type OrganizationCreationProps = {
onSuccess: () => void;
};
Expand All @@ -26,9 +24,11 @@ export function OrganizationCreation({ onSuccess }: OrganizationCreationProps) {
const createOrgMutation = useMutation({
mutationFn: async ({ organizationTitle, organizationSlug }: CreateOrganizationSchema) => {
return createOrganization(organizationTitle, organizationSlug, { isOnboardingFlow: true })
}
,
},
onSuccess: (data) => {
const { data: orgId } = data as { data: string }
console.log('created organization ID:', orgId);
Cookies.set('organization', orgId);
toast({ title: "Organization created!", description: "Your new organization is ready." });
onSuccess();
},
Expand Down

0 comments on commit 04acf2e

Please sign in to comment.