chore: mobile web view authentication signout cache in browser (#1361)

This commit is contained in:
guru_sainath
2024-10-07 13:31:39 +05:30
committed by sriram veeraghanta
parent 6521b1bb79
commit 1b0f45aaec
4 changed files with 68 additions and 6 deletions

View File

@@ -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:

View File

@@ -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<TMobileAuthEmailValidationForm> =
const handleFormSubmit = async (event: FormEvent<HTMLFormElement>) => {
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,
};

View File

@@ -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

View File

@@ -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<IUser> {
return this.axiosInstance
.get("/api/users/me/")
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async signOut(): Promise<void> {
return this.axiosInstance
.post("/auth/mobile/sign-out/", {})
.then((response) => response.data)
.catch((error) => {
throw error;
});
}
}
const mobileAuthService = new MobileAuthService();
export default mobileAuthService;