import {createSlice} from "@reduxjs/toolkit";
import * as SecureStore from 'expo-secure-store';
import {useDebugValue} from "react";

export interface AuthState {
    isAuthorized: boolean;
    accessToken?: string;
}

const initialState: AuthState = {
    isAuthorized: false,
    accessToken: undefined,
}

export const authSlice = createSlice({
    name: "auth",
    initialState,
    reducers: {
        login: (state, action) => {
            state.isAuthorized = true;
            state.accessToken = action.payload.accessToken;
        },
        logout: (state) => {
            state.isAuthorized = false;
            state.accessToken = undefined
        }
    }
});

export const {login, logout} = authSlice.actions;

export default authSlice.reducer;