-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
259 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Axios } from "axios"; | ||
|
||
|
||
|
||
class AxiosInterceptor { | ||
|
||
updatePostHeader = (credentials, instance) => instance.interceptors.request.use( | ||
(config) => { | ||
const hash = window.btoa(credentials.username+":"+credentials.password); | ||
const csrfToken = localStorage.getItem("X-XRSF-TOKEN"); | ||
if (hash) { | ||
instance.defaults.headers["Authorization"] = hash; | ||
} | ||
if(csrfToken) { | ||
instance.defaults.headers["X-XRSF-TOKEN"] = csrfToken; | ||
} | ||
return config | ||
} | ||
|
||
) | ||
} | ||
export default AxiosInterceptor; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from "react"; | ||
import axios from "axios"; | ||
|
||
|
||
|
||
|
||
|
||
|
||
class LoginService { | ||
|
||
|
||
login(user, instance) { | ||
if (user.username && user.password) { | ||
instance.interceptors.request.use((config) => { | ||
const hash = window.btoa(user.username+":"+user.password); | ||
if (hash) { | ||
let authHeader = "Basic "+hash; | ||
instance.defaults.headers["Authorization"] = authHeader; | ||
window.localStorage.setItem("Auth", authHeader); | ||
} | ||
|
||
return config | ||
}); | ||
}; | ||
|
||
instance.post("/user",user) | ||
.then((response) => { | ||
console.log(response); | ||
}) | ||
|
||
|
||
} | ||
}; | ||
export default new LoginService(); | ||
|
This file contains 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
Oops, something went wrong.