mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: social auth authentication workflow (#1264)
* fix: github login mutation * dev: updated social auth workflow and handled multiple loads on user * dev: mutaing user and updated analytics logout issue resolved --------- Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com>
This commit is contained in:
parent
49f19c2c44
commit
66807bef0d
@ -19,12 +19,14 @@ export const GithubLoginButton: FC<GithubLoginButtonProps> = (props) => {
|
||||
} = useRouter();
|
||||
// states
|
||||
const [loginCallBackURL, setLoginCallBackURL] = useState(undefined);
|
||||
const [gitCode, setGitCode] = useState<null | string>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (code) {
|
||||
if (code && !gitCode) {
|
||||
setGitCode(code.toString());
|
||||
handleSignIn(code.toString());
|
||||
}
|
||||
}, [code, handleSignIn]);
|
||||
}, [code, gitCode, handleSignIn]);
|
||||
|
||||
useEffect(() => {
|
||||
const origin =
|
||||
|
@ -24,6 +24,7 @@ const useUserAuth = (routeAuth: "sign-in" | "onboarding" | "admin" | null = "adm
|
||||
mutate,
|
||||
} = useSWR<ICurrentUserResponse>(CURRENT_USER, () => userService.currentUser(), {
|
||||
refreshInterval: 0,
|
||||
shouldRetryOnError: false,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -69,12 +69,13 @@ const Analytics = () => {
|
||||
useEffect(() => {
|
||||
if (!workspaceSlug) return;
|
||||
|
||||
trackEventServices.trackAnalyticsEvent(
|
||||
{ workspaceSlug: workspaceSlug?.toString() },
|
||||
"WORKSPACE_SCOPE_AND_DEMAND_ANALYTICS",
|
||||
user
|
||||
);
|
||||
}, [workspaceSlug]);
|
||||
if (user && workspaceSlug)
|
||||
trackEventServices.trackAnalyticsEvent(
|
||||
{ workspaceSlug: workspaceSlug?.toString() },
|
||||
"WORKSPACE_SCOPE_AND_DEMAND_ANALYTICS",
|
||||
user
|
||||
);
|
||||
}, [user, workspaceSlug]);
|
||||
|
||||
return (
|
||||
<WorkspaceAuthorizationLayout
|
||||
|
@ -30,13 +30,13 @@ const HomePage: NextPage = () => {
|
||||
const handleGoogleSignIn = async ({ clientId, credential }: any) => {
|
||||
try {
|
||||
if (clientId && credential) {
|
||||
mutateUser(
|
||||
await authenticationService.socialAuth({
|
||||
medium: "google",
|
||||
credential,
|
||||
clientId,
|
||||
})
|
||||
);
|
||||
const socialAuthPayload = {
|
||||
medium: "google",
|
||||
credential,
|
||||
clientId,
|
||||
};
|
||||
const response = await authenticationService.socialAuth(socialAuthPayload);
|
||||
if (response && response?.user) mutateUser();
|
||||
} else {
|
||||
throw Error("Cant find credentials");
|
||||
}
|
||||
@ -53,13 +53,13 @@ const HomePage: NextPage = () => {
|
||||
const handleGithubSignIn = async (credential: string) => {
|
||||
try {
|
||||
if (process.env.NEXT_PUBLIC_GITHUB_ID && credential) {
|
||||
mutateUser(
|
||||
await authenticationService.socialAuth({
|
||||
medium: "github",
|
||||
credential,
|
||||
clientId: process.env.NEXT_PUBLIC_GITHUB_ID,
|
||||
})
|
||||
);
|
||||
const socialAuthPayload = {
|
||||
medium: "github",
|
||||
credential,
|
||||
clientId: process.env.NEXT_PUBLIC_GITHUB_ID,
|
||||
};
|
||||
const response = await authenticationService.socialAuth(socialAuthPayload);
|
||||
if (response && response?.user) mutateUser();
|
||||
} else {
|
||||
throw Error("Cant find credentials");
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import Image from "next/image";
|
||||
import Router, { useRouter } from "next/router";
|
||||
import Router from "next/router";
|
||||
|
||||
import { mutate } from "swr";
|
||||
|
||||
@ -38,8 +37,6 @@ const Onboarding: NextPage = () => {
|
||||
|
||||
const [workspace, setWorkspace] = useState();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const { user, mutateUser } = useUserAuth("onboarding");
|
||||
|
||||
return (
|
||||
@ -89,21 +86,7 @@ const Onboarding: NextPage = () => {
|
||||
userService
|
||||
.updateUserOnBoard({ userRole }, user)
|
||||
.then(async () => {
|
||||
mutate<ICurrentUserResponse>(
|
||||
CURRENT_USER,
|
||||
(prevData) => {
|
||||
if (!prevData) return prevData;
|
||||
|
||||
return {
|
||||
...prevData,
|
||||
user: {
|
||||
...prevData.user,
|
||||
is_onboarded: true,
|
||||
},
|
||||
};
|
||||
},
|
||||
false
|
||||
);
|
||||
mutateUser();
|
||||
const userWorkspaces = await workspaceService.userWorkspaces();
|
||||
|
||||
const lastActiveWorkspace =
|
||||
|
Loading…
Reference in New Issue
Block a user