Commit 1e0e67f3 authored by Hadrien RENAUD's avatar Hadrien RENAUD

Add real connexion to api

parent 85bdf856
Pipeline #5905 passed with stages
in 2 minutes and 5 seconds
......@@ -75,13 +75,15 @@ WSGI_APPLICATION = 'api.wsgi.application'
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "postgres",
"USER": "postgres",
"HOST": "db",
"PORT": 5432,
}
}
# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
......@@ -123,12 +125,11 @@ ENV_PATH = os.path.abspath(os.path.dirname(__file__))
MEDIA_ROOT = "/usr/src"
MEDIA_URL = "api/media/"
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "postgres",
"USER": "postgres",
"HOST": "db",
"PORT": 5432,
}
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
]
}
CSRF_COOKIE_NAME = "XSRF-TOKEN"
export const API_BASE_URL = 'http://localhost/api';
import { User, Credentials } from "./User.types";
import { Api } from "../../services/api";
export function makeLoginRequest({ username }: Credentials): User {
return {
username: username,
};
const API_ROUTES = {
LOGIN: '/api-auth/login/',
LOGOUT: '/api-auth/logout',
RESET_PASSWORD: '/api-auth/password',
};
export async function makeLoginRequest(credentials: Credentials): Promise<User> {
await Api().post(API_ROUTES.LOGIN, credentials);
return { username: credentials.username }
}
export function makeLogoutRequest() {
export async function makeLogoutRequest() {
await Api().post(API_ROUTES.LOGOUT);
return;
}
export function makeForgotPasswordRequest(email: String) {
return;
export async function makeForgotPasswordRequest(email: String) {
return Api().post(API_ROUTES.RESET_PASSWORD);
}
export function makeResetPasswordRequest(password: String, token: String) {
......
import axios, { AxiosInstance } from 'axios';
import { API_BASE_URL } from '../config';
const createAxiosInstance = (): AxiosInstance => axios.create({
baseURL: API_BASE_URL,
timeout: 60000,
xsrfHeaderName: 'X-CSRFToken',
});
export class ApiInstance {
private static axiosInstance: AxiosInstance | null = null;
public static getInstance = (): AxiosInstance => {
if (!ApiInstance.axiosInstance) {
ApiInstance.axiosInstance = createAxiosInstance()
}
return ApiInstance.axiosInstance;
};
}
export const Api = ApiInstance.getInstance;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment