This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const slice = createSlice({ | |
name: 'auth', | |
initialState: { user: null, token: null, isAuthenticated: false } as AuthState, | |
reducers: { | |
logout: (state) => { | |
state.user = null | |
state.token = null | |
state.isAuthenticated = false | |
}, | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/example from https://redux-toolkit.js.org/rtk-query/usage/examples#authentication | |
export const api = createApi({ | |
baseQuery: fetchBaseQuery({ | |
baseUrl: '/', | |
prepareHeaders: (headers, { getState }) => { | |
// By default, if we have a token in the store, let's use that for authenticated requests | |
const token = (getState() as RootState).auth.token | |
if (token) { | |
headers.set('authorization', `Bearer ${token}`) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function App() { | |
return ( | |
<div className="App"> | |
<Header /> | |
<Routes> | |
<Route path="/" element={<Login />} /> | |
<Route path="*" element={<NotFound />} /> | |
<Route | |
path="dashboard" | |
element={<PrivateRoute roles={[ROLE.ADMIN]} component={Dashboard} />} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useSelector } from 'react-redux' | |
import { Navigate } from 'react-router-dom' | |
import AccessDenied from './pages/AccessDenied' | |
import { ROLE } from './features/auth/auth' | |
import { selectCurrentUser, selectIsAuthenticated } from './features/auth/authSlice' | |
interface Props { | |
component: React.ComponentType | |
path?: string | |
roles: Array<ROLE> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { render } from "react-dom"; | |
import "./style.scss"; | |
const App = () => { | |
return ( | |
<div> | |
<h1>Up and Running with Parcel</h1> | |
</div> | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "parcel-example", | |
"version": "1.0.0", | |
"description": "An example of Parcel bundler with React.js", | |
"main": "index.js", | |
"scripts": { | |
"dev": "parcel src/index.html", | |
"build": "rm -rf ./dist/ ; parcel build --out-dir dist/ src/index.html", | |
"mockdb": "json-server --watch mock/db.json", | |
"test": "echo \"Error: no test specified\" && exit 1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
admin: | |
access_log_path: /tmp/admin_access.log | |
address: | |
socket_address: { address: 0.0.0.0, port_value: 9901 } | |
static_resources: | |
listeners: | |
- name: listener_0 | |
address: | |
socket_address: { address: 0.0.0.0, port_value: 8080 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
AddCountryRequest, | |
AddCountryResponse, | |
GetCountriesRequest, | |
GetCountriesResponse, | |
Country | |
} from "./country_pb"; | |
import { CountryServiceClient } from "./country_grpc_web_pb"; | |
const host = "http://localhost:8080"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"log" | |
"net" | |
"google.golang.org/grpc" | |
pb "github.com/akursat/grpc-country/countrypb" | |
) | |
const ( | |
port = ":50051" |