mirror of
https://github.com/usebruno/bruno.git
synced 2025-06-21 20:41:41 +02:00
chore: cleanup unused files
This commit is contained in:
parent
22a14aa67a
commit
33f8900705
@ -1,23 +0,0 @@
|
|||||||
import { get, post, put } from './base';
|
|
||||||
|
|
||||||
// not used. kept as a placeholder for reference while implementing license key stuff
|
|
||||||
const AuthApi = {
|
|
||||||
whoami: () => get('auth/v1/user/whoami'),
|
|
||||||
signup: (params) => post('auth/v1/user/signup', params),
|
|
||||||
login: (params) => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const { ipcRenderer } = window.require('electron');
|
|
||||||
|
|
||||||
ipcRenderer
|
|
||||||
.invoke('bruno-account-request', {
|
|
||||||
data: params,
|
|
||||||
method: 'POST',
|
|
||||||
url: `${process.env.NEXT_PUBLIC_BRUNO_SERVER_API}/auth/v1/user/login`
|
|
||||||
})
|
|
||||||
.then(resolve)
|
|
||||||
.catch(reject);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default AuthApi;
|
|
@ -1,30 +0,0 @@
|
|||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
const apiClient = axios.create({
|
|
||||||
baseURL: process.env.NEXT_PUBLIC_GRAFNODE_SERVER_API
|
|
||||||
});
|
|
||||||
|
|
||||||
apiClient.interceptors.request.use(
|
|
||||||
(config) => {
|
|
||||||
const headers = {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
...config,
|
|
||||||
headers: headers
|
|
||||||
};
|
|
||||||
},
|
|
||||||
(error) => Promise.reject(error)
|
|
||||||
);
|
|
||||||
|
|
||||||
apiClient.interceptors.response.use(
|
|
||||||
(response) => response,
|
|
||||||
async (error) => {
|
|
||||||
return Promise.reject(error.response ? error.response.data : error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const { get, post, put, delete: destroy } = apiClient;
|
|
||||||
|
|
||||||
export { get, post, put, destroy };
|
|
@ -1,62 +0,0 @@
|
|||||||
import React, { useEffect, useReducer } from 'react';
|
|
||||||
import { useRouter } from 'next/router';
|
|
||||||
import AuthApi from 'api/auth';
|
|
||||||
import reducer from './reducer';
|
|
||||||
|
|
||||||
const AuthContext = React.createContext();
|
|
||||||
|
|
||||||
const initialState = {
|
|
||||||
isLoading: true,
|
|
||||||
lastStateTransition: null,
|
|
||||||
currentUser: null
|
|
||||||
};
|
|
||||||
|
|
||||||
export const AuthProvider = (props) => {
|
|
||||||
const router = useRouter();
|
|
||||||
const [state, dispatch] = useReducer(reducer, initialState);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
AuthApi.whoami()
|
|
||||||
.then((response) => {
|
|
||||||
let data = response.data;
|
|
||||||
dispatch({
|
|
||||||
type: 'WHOAMI_SUCCESS',
|
|
||||||
user: {
|
|
||||||
id: data.id,
|
|
||||||
name: data.name,
|
|
||||||
username: data.username
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
dispatch({
|
|
||||||
type: 'WHOAMI_ERROR',
|
|
||||||
error: error
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (state.lastStateTransition === 'LOGIN_SUCCESS') {
|
|
||||||
router.push('/');
|
|
||||||
}
|
|
||||||
if (state.lastStateTransition === 'WHOAMI_ERROR') {
|
|
||||||
// Todo: decide action
|
|
||||||
// router.push('/login');
|
|
||||||
}
|
|
||||||
}, [state]);
|
|
||||||
|
|
||||||
return <AuthContext.Provider value={[state, dispatch]} {...props} />;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useAuth = () => {
|
|
||||||
const context = React.useContext(AuthContext);
|
|
||||||
|
|
||||||
if (context === undefined) {
|
|
||||||
throw new Error(`useAuth must be used within a AuthProvider`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return context;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default AuthProvider;
|
|
@ -1,43 +0,0 @@
|
|||||||
import produce from 'immer';
|
|
||||||
|
|
||||||
const reducer = (state, action) => {
|
|
||||||
switch (action.type) {
|
|
||||||
case 'WHOAMI_SUCCESS': {
|
|
||||||
return produce(state, (draft) => {
|
|
||||||
draft.isLoading = false;
|
|
||||||
draft.currentUser = action.user;
|
|
||||||
draft.lastStateTransition = 'WHOAMI_SUCCESS';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'WHOAMI_ERROR': {
|
|
||||||
return produce(state, (draft) => {
|
|
||||||
draft.isLoading = false;
|
|
||||||
draft.currentUser = null;
|
|
||||||
draft.lastStateTransition = 'WHOAMI_ERROR';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'LOGIN_SUCCESS': {
|
|
||||||
return produce(state, (draft) => {
|
|
||||||
draft.isLoading = false;
|
|
||||||
draft.currentUser = action.user;
|
|
||||||
draft.lastStateTransition = 'LOGIN_SUCCESS';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'LOGOUT_SUCCESS': {
|
|
||||||
return produce(state, (draft) => {
|
|
||||||
draft.isLoading = false;
|
|
||||||
draft.currentUser = null;
|
|
||||||
draft.lastStateTransition = 'LOGOUT_SUCCESS';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
default: {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default reducer;
|
|
Loading…
x
Reference in New Issue
Block a user