This file contains hidden or 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
interface TokenResponse { | |
token: string; | |
} | |
export interface Credentials { | |
username: string; | |
password: string; | |
} | |
const BASE_URL = "http://localhost:8000"; |
This file contains hidden or 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, { useState } from "react"; | |
import { Redirect } from "react-router-dom"; | |
import { useDispatch } from "react-redux"; | |
import { logIn } from "../store/auth/actions"; | |
import { Credentials, getToken } from "../api/auth"; | |
import { useAuthenticated } from "../store/auth/hooks"; | |
function Login() { |
This file contains hidden or 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 { Route, Redirect } from "react-router-dom"; | |
import { useAuthenticated } from "../store/auth/hooks"; | |
function PrivateRoute({ | |
children, | |
...rest | |
}: { | |
children: JSX.Element | JSX.Element[]; |
This file contains hidden or 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 { AuthState } from "./types"; | |
export const useAuthenticated = (): boolean => | |
useSelector(({ auth }: { auth: AuthState }) => auth.isAuthenticated); | |
export const useToken = (): string | undefined => | |
useSelector(({ auth }: { auth: AuthState }) => auth.token); |
This file contains hidden or 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 { createLogger } from "redux-logger"; | |
import storage from "redux-persist/lib/storage"; | |
import { persistStore, persistReducer } from "redux-persist"; | |
import { compose, createStore, applyMiddleware } from "redux"; | |
import { rootReducer } from "./reducer"; | |
const persistConfig = { | |
key: "root", | |
storage: storage, |
This file contains hidden or 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 { LOGIN, LOGOUT, LoginAction, LogoutAction } from "./types"; | |
export const logIn = (token: string, username: string): LoginAction => ({ | |
type: LOGIN, | |
payload: { token, username }, | |
}); | |
export const logOut = (): LogoutAction => ({ | |
type: LOGOUT, | |
}); |
This file contains hidden or 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 { LOGIN, LOGOUT, AuthState, AuthActionType } from "./types"; | |
const initialState: AuthState = { | |
isAuthenticated: false, | |
}; | |
const authReducer = ( | |
state: AuthState = initialState, | |
action: AuthActionType | |
): AuthState => { |
This file contains hidden or 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
export const LOGIN = "LOGIN"; | |
export const LOGOUT = "LOGOUT"; | |
export interface AuthState { | |
token?: string; | |
username?: string; | |
isAuthenticated: boolean; | |
} | |
interface LoginPayload { |
This file contains hidden or 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
from __future__ import annotations | |
from django.db import models | |
from django.contrib.auth.models import AbstractUser | |
class FollowRequest(models.Model): | |
to_follow = models.ForeignKey( | |
'user.User', on_delete=models.CASCADE, related_name='requests' |
This file contains hidden or 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
class PostDetailView(DetailView): | |
model = Post | |
slug_field = 'slug' | |
slug_url_kwarg = 'post' | |
context_object_name = 'post' | |
template_name = 'blog/post/detail.html' | |
def get_queryset(self): | |
return self.model.objects.filter( | |
publish__day=self.kwargs['day'], |