diff --git a/apiserver/plane/authentication/views/app/mobile/signout.py b/apiserver/plane/authentication/views/app/mobile/signout.py index 28f0b50305..7dd7537f0e 100644 --- a/apiserver/plane/authentication/views/app/mobile/signout.py +++ b/apiserver/plane/authentication/views/app/mobile/signout.py @@ -10,9 +10,14 @@ from rest_framework.views import APIView # Module imports from plane.authentication.utils.host import user_ip from plane.db.models import User +from plane.app.authentication.session import BaseSessionAuthentication class MobileSignOutAuthEndpoint(APIView): + authentication_classes = [ + BaseSessionAuthentication, + ] + def post(self, request): # Get user try: diff --git a/web/ee/components/mobile/authentication/forms/email-confirmation.tsx b/web/ee/components/mobile/authentication/forms/email-confirmation.tsx index 5877d7e23e..69ac121531 100644 --- a/web/ee/components/mobile/authentication/forms/email-confirmation.tsx +++ b/web/ee/components/mobile/authentication/forms/email-confirmation.tsx @@ -14,6 +14,8 @@ import { } from "@/helpers/authentication.helper"; import { cn } from "@/helpers/common.helper"; import { checkEmailValidity } from "@/helpers/string.helper"; +// plane web services +import mobileAuthService from "@/plane-web/services/mobile.service"; // services import { AuthService } from "@/services/auth.service"; @@ -47,9 +49,28 @@ export const MobileAuthEmailValidationForm: FC = const handleFormSubmit = async (event: FormEvent) => { event.preventDefault(); + let isUserSignOut = false; + try { + await mobileAuthService.currentUser(); + isUserSignOut = true; + } catch (error) { + console.error(error); + } + + let isEmailShouldBeVerified = true; + if (isUserSignOut) { + try { + await mobileAuthService.signOut(); + } catch (error) { + console.error(error); + isEmailShouldBeVerified = false; + } + } + + if (!isEmailShouldBeVerified) return; + handleEmail(email); setIsSubmitting(true); - const payload: IEmailCheckData = { email: email, }; diff --git a/web/ee/components/mobile/authentication/root.tsx b/web/ee/components/mobile/authentication/root.tsx index 32c6c49bff..a8c965c426 100644 --- a/web/ee/components/mobile/authentication/root.tsx +++ b/web/ee/components/mobile/authentication/root.tsx @@ -3,6 +3,8 @@ import { FC, useEffect, useState } from "react"; import { observer } from "mobx-react"; import { useSearchParams } from "next/navigation"; +// components +import { AuthBanner } from "@/components/account"; // helpers import { authErrorHandler, @@ -11,12 +13,8 @@ import { EErrorAlertType, TAuthErrorInfo, } from "@/helpers/authentication.helper"; -// components -import { AuthBanner } from "@/components/account"; // hooks import { useInstance } from "@/hooks/store"; -// services -import { AuthService } from "@/services/auth.service"; // plane web components import { MobileTermsAndConditions, @@ -24,6 +22,8 @@ import { MobileAuthUniqueCodeForm, MobileAuthPasswordForm, } from "@/plane-web/components/mobile"; +// services +import { AuthService } from "@/services/auth.service"; // service initialization const authService = new AuthService(); @@ -53,7 +53,7 @@ const UNIQUE_CODE_ERROR_CODES = [ const PASSWORD_ERROR_CODES = [EAuthenticationErrorCodes.AUTHENTICATION_FAILED_SIGN_IN]; -export const AuthRoot: FC = observer((props) => { +export const AuthRoot: FC = observer(() => { // router const searchParams = useSearchParams(); // query params diff --git a/web/ee/services/mobile.service.ts b/web/ee/services/mobile.service.ts new file mode 100644 index 0000000000..e05756f82d --- /dev/null +++ b/web/ee/services/mobile.service.ts @@ -0,0 +1,36 @@ +import axios, { AxiosInstance } from "axios"; +import { IUser } from "@plane/types"; +// helpers +import { API_BASE_URL } from "@/helpers/common.helper"; + +export class MobileAuthService { + axiosInstance: AxiosInstance; + constructor() { + this.axiosInstance = axios.create({ + baseURL: API_BASE_URL, + withCredentials: true, + }); + } + + async currentUser(): Promise { + return this.axiosInstance + .get("/api/users/me/") + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + async signOut(): Promise { + return this.axiosInstance + .post("/auth/mobile/sign-out/", {}) + .then((response) => response.data) + .catch((error) => { + throw error; + }); + } +} + +const mobileAuthService = new MobileAuthService(); + +export default mobileAuthService;