import { createSlice } from '@reduxjs/toolkit'; import type { RootState } from '../../store'; import { User } from '../../apiSlice'; type AuthState = { user: User | null id: number | null token: string | null } const authSlice = createSlice({ name: 'auth', initialState: { user: null, token: null, id: null } as AuthState, reducers: { setCredentials: (state, action) => { const { user, token, id } = action.payload; state.user = user; state.id = id; state.token = token; } } }); export const { setCredentials } = authSlice.actions; export default authSlice.reducer; export const selectCurrentUser = (state: RootState) => state.auth.user;