Skip to content

Commit 82767da

Browse files
authored
Merge pull request #39 from velt-js/master-sample-app-all-demos-fix
Sign Out User Fix
2 parents a5437fd + 0741294 commit 82767da

File tree

17 files changed

+170
-17
lines changed

17 files changed

+170
-17
lines changed

apps/react/comments/dashboard/custom/dashboard-demo/components/velt/VeltCollaboration.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22
import { useVeltClient, VeltComments } from "@veltdev/react";
33
import VeltInitializeDocument from "./VeltInitializeDocument";
44
import { VeltCustomization } from "./ui-customization/VeltCustomization";
5-
import { useEffect } from "react";
5+
import { useEffect, useRef } from "react";
66
import { useAppUser } from "@/app/userAuth/AppUserContext";
77

88
export function VeltCollaboration() {
99
const { isUserLoggedIn } = useAppUser();
1010
// [Velt] Get Velt client instance
1111
const { client } = useVeltClient();
12+
const hasSignedOutOnMount = useRef(false);
13+
14+
// [Velt] Sign out any previous user on mount to clear stale state
15+
useEffect(() => {
16+
if (!hasSignedOutOnMount.current && client) {
17+
hasSignedOutOnMount.current = true;
18+
client.signOutUser();
19+
}
20+
}, [client]);
1221

1322
// [Velt] Sign out user when user logs out, getting user login state from host app
1423
useEffect(() => {

apps/react/comments/dashboard/inline-comments/dashboard-inline-comments-demo/components/velt/VeltCollaboration.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22
import { useVeltClient, VeltComments, VeltCommentsSidebar } from "@veltdev/react";
33
import VeltInitializeDocument from "./VeltInitializeDocument";
44
import { VeltCustomization } from "./ui-customization/VeltCustomization";
5-
import { useEffect } from "react";
5+
import { useEffect, useRef } from "react";
66
import { useAppUser } from "@/app/userAuth/AppUserContext";
77

88
export function VeltCollaboration() {
99
const { isUserLoggedIn } = useAppUser();
1010
// [Velt] Get Velt client instance
1111
const { client } = useVeltClient();
12+
const hasSignedOutOnMount = useRef(false);
13+
14+
// [Velt] Sign out any previous user on mount to clear stale state
15+
useEffect(() => {
16+
if (!hasSignedOutOnMount.current && client) {
17+
hasSignedOutOnMount.current = true;
18+
client.signOutUser();
19+
}
20+
}, [client]);
1221

1322
// [Velt] Sign out user when user logs out, getting user login state from host app
1423
useEffect(() => {

apps/react/comments/dashboard/self-hosting/dashboard-mongo-db-demo/components/velt/VeltCollaboration.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22
import { useAppUser } from "@/app/userAuth/AppUserContext";
33
import { useVeltClient, VeltComments, VeltCommentsSidebar } from "@veltdev/react";
4-
import { useEffect } from "react";
4+
import { useEffect, useRef } from "react";
55
import VeltInitializeDocument from "./VeltInitializeDocument";
66
import { VeltCustomization } from "./ui-customization/VeltCustomization";
77
import { useSelectedJob } from "@/app/document/JobsContext";
@@ -10,9 +10,18 @@ export function VeltCollaboration() {
1010
const { isUserLoggedIn } = useAppUser();
1111
// [Velt] Get Velt client instance
1212
const { client } = useVeltClient();
13+
const hasSignedOutOnMount = useRef(false);
1314

1415
const selectedJob = useSelectedJob();
1516

17+
// [Velt] Sign out any previous user on mount to clear stale state
18+
useEffect(() => {
19+
if (!hasSignedOutOnMount.current && client) {
20+
hasSignedOutOnMount.current = true;
21+
client.signOutUser();
22+
}
23+
}, [client]);
24+
1625
// [Velt] Sign out user when user logs out, getting user login state from host app
1726
useEffect(() => {
1827
if (isUserLoggedIn === false && client) {

apps/react/comments/dashboard/self-hosting/dashboard-postgres-demo/components/velt/VeltCollaboration.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22
import { useAppUser } from "@/app/userAuth/AppUserContext";
33
import { useVeltClient, VeltComments, VeltCommentsSidebar } from "@veltdev/react";
4-
import { useEffect } from "react";
4+
import { useEffect, useRef } from "react";
55
import VeltInitializeDocument from "./VeltInitializeDocument";
66
import { VeltCustomization } from "./ui-customization/VeltCustomization";
77
import { useSelectedJob } from "@/app/document/JobsContext";
@@ -10,9 +10,18 @@ export function VeltCollaboration() {
1010
const { isUserLoggedIn } = useAppUser();
1111
// [Velt] Get Velt client instance
1212
const { client } = useVeltClient();
13+
const hasSignedOutOnMount = useRef(false);
1314

1415
const selectedJob = useSelectedJob();
1516

17+
// [Velt] Sign out any previous user on mount to clear stale state
18+
useEffect(() => {
19+
if (!hasSignedOutOnMount.current && client) {
20+
hasSignedOutOnMount.current = true;
21+
client.signOutUser();
22+
}
23+
}, [client]);
24+
1625
// [Velt] Sign out user when user logs out, getting user login state from host app
1726
useEffect(() => {
1827
if (isUserLoggedIn === false && client) {

apps/react/comments/tables/ag-grid/comment-aggregation/components/velt/VeltCollaboration.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22
import { useVeltClient, VeltComments, VeltCommentsSidebar } from "@veltdev/react";
33
import VeltInitializeDocument from "./VeltInitializeDocument";
44
import { VeltCustomization } from "./ui-customization/VeltCustomization";
5-
import { useEffect } from "react";
5+
import { useEffect, useRef } from "react";
66
import { useAppUser } from "@/app/userAuth/AppUserContext";
77

88
export function VeltCollaboration() {
99
const { isUserLoggedIn } = useAppUser();
1010
// [Velt] Get Velt client instance
1111
const { client } = useVeltClient();
12+
const hasSignedOutOnMount = useRef(false);
13+
14+
// [Velt] Sign out any previous user on mount to clear stale state
15+
useEffect(() => {
16+
if (!hasSignedOutOnMount.current && client) {
17+
hasSignedOutOnMount.current = true;
18+
client.signOutUser();
19+
}
20+
}, [client]);
1221

1322
// [Velt] Sign out user when user logs out, getting user login state from host app
1423
useEffect(() => {

apps/react/comments/tables/ag-grid/multiple-tools/components/velt/VeltCollaboration.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22
import { useVeltClient, VeltComments, VeltCommentsSidebar } from "@veltdev/react";
33
import VeltInitializeDocument from "./VeltInitializeDocument";
44
import { VeltCustomization } from "./ui-customization/VeltCustomization";
5-
import { useEffect } from "react";
5+
import { useEffect, useRef } from "react";
66
import { useAppUser } from "@/app/userAuth/AppUserContext";
77

88
export function VeltCollaboration() {
99
const { isUserLoggedIn } = useAppUser();
1010
const { client } = useVeltClient();
11+
const hasSignedOutOnMount = useRef(false);
12+
13+
// [Velt] Sign out any previous user on mount to clear stale state
14+
useEffect(() => {
15+
if (!hasSignedOutOnMount.current && client) {
16+
hasSignedOutOnMount.current = true;
17+
client.signOutUser();
18+
}
19+
}, [client]);
1120

1221
// [Velt] Sign out user when user logs out, getting user login state from host app
1322
useEffect(() => {

apps/react/comments/tables/ag-grid/single-tool/components/velt/VeltCollaboration.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22
import { useVeltClient, VeltComments, VeltCommentsSidebar } from "@veltdev/react";
33
import VeltInitializeDocument from "./VeltInitializeDocument";
44
import { VeltCustomization } from "./ui-customization/VeltCustomization";
5-
import { useEffect } from "react";
5+
import { useEffect, useRef } from "react";
66
import { useAppUser } from "@/app/userAuth/AppUserContext";
77

88
export function VeltCollaboration() {
99
const { isUserLoggedIn } = useAppUser();
1010
const { client } = useVeltClient();
11+
const hasSignedOutOnMount = useRef(false);
12+
13+
// [Velt] Sign out any previous user on mount to clear stale state
14+
useEffect(() => {
15+
if (!hasSignedOutOnMount.current && client) {
16+
hasSignedOutOnMount.current = true;
17+
client.signOutUser();
18+
}
19+
}, [client]);
1120

1221
// [Velt] Sign out user when user logs out, getting user login state from host app
1322
useEffect(() => {

apps/react/comments/tables/tanstack/comment-aggregation/components/velt/VeltCollaboration.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22
import { useVeltClient, VeltComments, VeltCommentsSidebar } from "@veltdev/react";
33
import VeltInitializeDocument from "./VeltInitializeDocument";
44
import { VeltCustomization } from "./ui-customization/VeltCustomization";
5-
import { useEffect } from "react";
5+
import { useEffect, useRef } from "react";
66
import { useAppUser } from "@/app/userAuth/AppUserContext";
77

88
export function VeltCollaboration() {
99
const { isUserLoggedIn } = useAppUser();
1010
// [Velt] Get Velt client instance
1111
const { client } = useVeltClient();
12+
const hasSignedOutOnMount = useRef(false);
13+
14+
// [Velt] Sign out any previous user on mount to clear stale state
15+
useEffect(() => {
16+
if (!hasSignedOutOnMount.current && client) {
17+
hasSignedOutOnMount.current = true;
18+
client.signOutUser();
19+
}
20+
}, [client]);
1221

1322
// [Velt] Sign out user when user logs out, getting user login state from host app
1423
useEffect(() => {

apps/react/comments/tables/tanstack/multiple-tools/components/velt/VeltCollaboration.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22
import { useVeltClient, VeltComments, VeltCommentsSidebar } from "@veltdev/react";
33
import VeltInitializeDocument from "./VeltInitializeDocument";
44
import { VeltCustomization } from "./ui-customization/VeltCustomization";
5-
import { useEffect } from "react";
5+
import { useEffect, useRef } from "react";
66
import { useAppUser } from "@/app/userAuth/AppUserContext";
77

88
export function VeltCollaboration() {
99
const { isUserLoggedIn } = useAppUser();
1010
// [Velt] Get Velt client instance
1111
const { client } = useVeltClient();
12+
const hasSignedOutOnMount = useRef(false);
13+
14+
// [Velt] Sign out any previous user on mount to clear stale state
15+
useEffect(() => {
16+
if (!hasSignedOutOnMount.current && client) {
17+
hasSignedOutOnMount.current = true;
18+
client.signOutUser();
19+
}
20+
}, [client]);
1221

1322
// [Velt] Sign out user when user logs out, getting user login state from host app
1423
useEffect(() => {

apps/react/comments/tables/tanstack/single-tool/components/velt/VeltCollaboration.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22
import { useVeltClient, VeltComments, VeltCommentsSidebar } from "@veltdev/react";
33
import VeltInitializeDocument from "./VeltInitializeDocument";
44
import { VeltCustomization } from "./ui-customization/VeltCustomization";
5-
import { useEffect } from "react";
5+
import { useEffect, useRef } from "react";
66
import { useAppUser } from "@/app/userAuth/AppUserContext";
77

88
export function VeltCollaboration() {
99
const { isUserLoggedIn } = useAppUser();
1010
const { client } = useVeltClient();
11+
const hasSignedOutOnMount = useRef(false);
12+
13+
// [Velt] Sign out any previous user on mount to clear stale state
14+
useEffect(() => {
15+
if (!hasSignedOutOnMount.current && client) {
16+
hasSignedOutOnMount.current = true;
17+
client.signOutUser();
18+
}
19+
}, [client]);
1120

1221
// [Velt] Sign out user when user logs out, getting user login state from host app
1322
useEffect(() => {

0 commit comments

Comments
 (0)