On AWS, the backend doesn’t read JWT cookies. Login succeeds but API calls return 403. See revised code examples below:
export const loadUserProfile = createAsyncThunk(
'user/loadProfile',
async (_, { rejectWithError }) => {
try {
const reply = await axios.get(`${API_SERVICE}/user/profile`, { withCredentials: true });
return reply.data;
} catch (error) {
return rejectWithError(error.response?.data);
}
}
);
import jwt from 'jsonwebtoken';
const issueJwt = (uid, res) => {
const jwtToken = jwt.sign({ uid }, process.env.SECRET_KEY, { expiresIn: '10d' });
res.cookie('authToken', jwtToken, {
maxAge: 10 * 24 * 3600 * 1000,
httpOnly: true,
sameSite: 'lax',
secure: true
});
};
export default issueJwt;