Skip to content

Instantly share code, notes, and snippets.

View akursat's full-sized avatar
🚀
typeof null === "object"

A. Kürşat Uzun akursat

🚀
typeof null === "object"
View GitHub Profile
@akursat
akursat / authSlice.ts
Created September 20, 2021 07:51
redux toolkit authslice
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
},
},
@akursat
akursat / auth.ts
Created September 20, 2021 07:41
Rtk query authentication
/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}`)
}
@akursat
akursat / App.tsx
Last active November 22, 2021 18:19
react router v6 private route usage
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} />}
@akursat
akursat / PrivateRoute.tsx
Last active November 22, 2021 18:19
React router v6 PrivateRoute
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>
import React from "react";
import { render } from "react-dom";
import "./style.scss";
const App = () => {
return (
<div>
<h1>Up and Running with Parcel</h1>
</div>
);
{
"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"
@akursat
akursat / envoy.yaml
Created February 6, 2020 14:46
grpcWeb example
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 }
@akursat
akursat / index.js
Created February 6, 2020 14:36
grpc-web example
import {
AddCountryRequest,
AddCountryResponse,
GetCountriesRequest,
GetCountriesResponse,
Country
} from "./country_pb";
import { CountryServiceClient } from "./country_grpc_web_pb";
const host = "http://localhost:8080";
@akursat
akursat / main.go
Created February 6, 2020 11:29
example grpc go server
package main
import (
"context"
"log"
"net"
"google.golang.org/grpc"
pb "github.com/akursat/grpc-country/countrypb"
)
const (
port = ":50051"