Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { createContext, useState } from "react";
- import axios from "axios";
- export const ApplicationContext = createContext();
- const ApplicationContextProvider = (props) => {
- const [globalstate, setGlobalstate] = useState({
- error: null,
- token: null,
- IsAuth: false,
- });
- // const [token, setToken] = useState(null);
- // const [error, setError] = useState(null)
- const LoginUsers = (email, password) => {
- // axios
- // .post("http://127.0.0.1:8000/token", {
- // username: email,
- // password: password,
- // })
- // .then((response) => {
- // console.log(response.data);
- // //const expirationDate = new
- // })
- // .catch((error) => {
- // console.log(error);
- // });
- //
- fetch(
- `http://127.0.0.1:8000/token?username=${email}&password=${password}`,
- {
- method: "POST",
- headers: {
- "Content-Type": "application/x-www-form-urlencoded",
- accept: "application/json",
- //"sec-fetch-site": "same-origin",
- "X-CSRFToken": "csrftoken",
- },
- //body: JSON.stringify({ username: email, password: password }),
- }
- )
- .then((response) => {
- console.log(response);
- })
- .catch((error) => {
- console.log(error);
- });
- };
- return (
- <ApplicationContext.Provider value={{ globalstate, LoginUsers }}>
- {props.children}
- </ApplicationContext.Provider>
- );
- };
- export default ApplicationContextProvider;
Add Comment
Please, Sign In to add comment