Skip to content

Commit bcddb31

Browse files
committedFeb 9, 2023
removes axios completely
1 parent e4c3cc7 commit bcddb31

File tree

3 files changed

+13
-96
lines changed

3 files changed

+13
-96
lines changed
 

‎class-39/demo/cookie-stand-admin/contexts/auth.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createContext, useContext, useState } from 'react';
22
import jwt from 'jsonwebtoken';
3-
import axios from 'axios';
43
const baseUrl = process.env.NEXT_PUBLIC_API_URL;
54
const tokenUrl = baseUrl + '/api/token/';
65

@@ -25,12 +24,22 @@ export function AuthProvider(props) {
2524

2625
async function login(username, password) {
2726

28-
const response = await axios.post(tokenUrl, { username, password });
27+
// const response = await axios.post(tokenUrl, { username, password });
2928

30-
const decodedAccess = jwt.decode(response.data.access);
29+
const options = {
30+
method: "POST",
31+
body: JSON.stringify({username, password}),
32+
headers: {'Content-Type': 'application/json'},
33+
};
34+
35+
const response = await fetch(tokenUrl, options);
36+
37+
const data = await response.json();
38+
39+
const decodedAccess = jwt.decode(data.access);
3140

3241
const newState = {
33-
tokens: response.data,
42+
tokens: data,
3443
user: {
3544
username: decodedAccess.username,
3645
email: decodedAccess.email,

‎class-39/demo/cookie-stand-admin/package-lock.json

-91
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎class-39/demo/cookie-stand-admin/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
},
1111
"dependencies": {
1212
"@next/font": "13.1.6",
13-
"axios": "^1.3.2",
1413
"eslint": "8.33.0",
1514
"eslint-config-next": "13.1.6",
1615
"jsonwebtoken": "^9.0.0",

0 commit comments

Comments
 (0)
Please sign in to comment.