chore: update auth service

This commit is contained in:
Steven
2023-11-23 22:02:19 +08:00
parent 38e5398cb9
commit b7999a4db2
10 changed files with 65 additions and 110 deletions

View File

@ -17,7 +17,6 @@
"copy-to-clipboard": "^3.3.3",
"dayjs": "^1.11.10",
"i18next": "^23.7.6",
"js-cookie": "^3.0.5",
"lodash-es": "^4.17.21",
"lucide-react": "^0.292.0",
"nice-grpc-web": "^3.3.2",
@ -34,7 +33,6 @@
"devDependencies": {
"@bufbuild/buf": "^1.28.1",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/js-cookie": "^3.0.6",
"@types/lodash-es": "^4.17.11",
"@types/react": "^18.2.38",
"@types/react-dom": "^18.2.16",

View File

@ -29,9 +29,6 @@ dependencies:
i18next:
specifier: ^23.7.6
version: 23.7.6
js-cookie:
specifier: ^3.0.5
version: 3.0.5
lodash-es:
specifier: ^4.17.21
version: 4.17.21
@ -76,9 +73,6 @@ devDependencies:
'@trivago/prettier-plugin-sort-imports':
specifier: ^4.3.0
version: 4.3.0(prettier@2.6.2)
'@types/js-cookie':
specifier: ^3.0.6
version: 3.0.6
'@types/lodash-es':
specifier: ^4.17.11
version: 4.17.11
@ -1151,10 +1145,6 @@ packages:
resolution: {integrity: sha512-aLkWa0C0vO5b4Sr798E26QgOkss68Un0bLjs7u9qxzPT5CG+8DuNTffWES58YzJs3hrVAOs1wonycqEBqNJubA==}
dev: false
/@types/js-cookie@3.0.6:
resolution: {integrity: sha512-wkw9yd1kEXOPnvEeEV1Go1MmxtBJL0RR79aOTAApecWFVu7w0NNXNqhcWgvw2YgZDYadliXkl14pa3WXw5jlCQ==}
dev: true
/@types/json-schema@7.0.15:
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
dev: true
@ -2580,11 +2570,6 @@ packages:
resolution: {integrity: sha512-HvdH2LzI/EAZcUwA8+0nKNtWHqS+ZmijLA30RwZA0bo7ToCckjK5MkGhjED9KoRcXO6BaGI3I9UIzSA1FKFPOQ==}
dev: false
/js-cookie@3.0.5:
resolution: {integrity: sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==}
engines: {node: '>=14'}
dev: false
/js-tokens@4.0.0:
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}

View File

@ -6,7 +6,6 @@ import { authServiceClient } from "@/grpcweb";
import useWorkspaceStore from "@/stores/v1/workspace";
import { PlanType } from "@/types/proto/api/v2/subscription_service";
import { Role } from "@/types/proto/api/v2/user_service";
import { removeAccessToken } from "@/utils/auth";
import useUserStore from "../stores/v1/user";
import AboutDialog from "./AboutDialog";
import Icon from "./Icon";
@ -24,7 +23,6 @@ const Header: React.FC = () => {
const handleSignOutButtonClick = async () => {
await authServiceClient.signOut({});
removeAccessToken();
localStorage.removeItem("userId");
window.location.href = "/auth";
};

View File

@ -7,7 +7,6 @@ import { authServiceClient } from "@/grpcweb";
import useNavigateTo from "@/hooks/useNavigateTo";
import useUserStore from "@/stores/v1/user";
import useWorkspaceStore from "@/stores/v1/workspace";
import { setAccessToken } from "@/utils/auth";
import useLoading from "../hooks/useLoading";
const SignIn: React.FC = () => {
@ -45,11 +44,9 @@ const SignIn: React.FC = () => {
try {
actionBtnLoadingState.setLoading();
const { user, accessToken } = await authServiceClient.signIn({ email, password });
const { user } = await authServiceClient.signIn({ email, password });
if (user) {
userStore.setCurrentUserId(user.id);
console.log("accessToken", accessToken);
setAccessToken(accessToken);
await userStore.fetchCurrentUser();
navigateTo("/");
} else {

View File

@ -7,7 +7,6 @@ import { authServiceClient } from "@/grpcweb";
import useNavigateTo from "@/hooks/useNavigateTo";
import useUserStore from "@/stores/v1/user";
import useWorkspaceStore from "@/stores/v1/workspace";
import { setAccessToken } from "@/utils/auth";
import useLoading from "../hooks/useLoading";
const SignUp: React.FC = () => {
@ -52,14 +51,13 @@ const SignUp: React.FC = () => {
try {
actionBtnLoadingState.setLoading();
const { user, accessToken } = await authServiceClient.signUp({
const { user } = await authServiceClient.signUp({
email,
nickname,
password,
});
if (user) {
userStore.setCurrentUserId(user.id);
setAccessToken(accessToken);
await userStore.fetchCurrentUser();
navigateTo("/");
} else {

View File

@ -1,9 +0,0 @@
import Cookies from "js-cookie";
export const setAccessToken = (token: string) => {
Cookies.set("slash.access-token", token, { path: "/", expires: 365 });
};
export const removeAccessToken = () => {
Cookies.remove("slash.access-token", { path: "/", expires: 365 });
};