Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import posthog from "posthog-js"; import { LOGIN } from "../../../../constants/index.ts"; import { apiSlice } from "../../../app/apiSlice.ts"; import { setCredentials } from "../authSlice.ts"; export const loginApi = apiSlice.injectEndpoints({ endpoints: (builder) => ({ login: builder.mutation<any, any>({ query: ({ email, password }) => ({ url: LOGIN, method: "POST", body: { email: email, password: password, }, }), onQueryStarted: async (args, { dispatch, queryFulfilled }) => { try { const email = args.email; const { data } = await queryFulfilled; const accessToken = data?.access_token; const refreshToken = data?.refresh_token; dispatch(setCredentials({ accessToken, refreshToken, email })); localStorage.setItem("email", email); localStorage.setItem("access_token", accessToken); localStorage.setItem("refresh_token", accessToken); posthog.identify(email); } catch (error) { // Handle any errors console.log(error); } }, }), }), }); export const { useLoginMutation } = loginApi; |