summaryrefslogtreecommitdiff
path: root/src/features/auth/authSlice.ts
diff options
context:
space:
mode:
authorMichael Hunteman <michael@huntm.net>2024-02-24 10:04:10 -0600
committerMichael Hunteman <michael@huntm.net>2024-02-24 10:18:33 -0600
commit68a86b2f9c41717767443b6b9e1860cb73b2aa30 (patch)
tree33c8d6033a26ec70a1e116d2e1669f2dc12b3744 /src/features/auth/authSlice.ts
parent589e53f152d7363074049dfd1bd5a34286ae74d6 (diff)
Use RTK query
Diffstat (limited to 'src/features/auth/authSlice.ts')
-rw-r--r--src/features/auth/authSlice.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/features/auth/authSlice.ts b/src/features/auth/authSlice.ts
new file mode 100644
index 0000000..9716131
--- /dev/null
+++ b/src/features/auth/authSlice.ts
@@ -0,0 +1,25 @@
+import { createSlice } from '@reduxjs/toolkit';
+import type { RootState } from '../../store';
+
+type AuthState = {
+ user: User | null
+ token: string | null
+}
+
+const authSlice = createSlice({
+ name: 'auth',
+ initialState: { user: null, token: null } as AuthState,
+ reducers: {
+ setCredentials: (state, action) => {
+ const { user, token } = action.payload;
+ state.user = user;
+ state.token = token;
+ }
+ }
+});
+
+export const { setCredentials } = authSlice.actions;
+
+export default authSlice.reducer;
+
+export const selectCurrentUser = (state: RootState) => state.auth.user;