-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
8c8b807
commit c160875
Showing
4 changed files
with
43 additions
and
5 deletions.
There are no files selected for viewing
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,8 @@ | ||
import React, { useState, useEffect } from "react"; | ||
|
||
export default function CartContent(){ | ||
const [token, setToken] = useState(""); | ||
|
||
useEffect(() => {}, []); | ||
return <div> JWT {token} </div> ; | ||
} |
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,17 @@ | ||
import { BehaviourSubject} from "rxjs"; | ||
|
||
const API_SERVER = "http://localhost:8080"; | ||
export const jwt = new BehaviourSubject(null); | ||
|
||
// Not dealing with route protection/ error routes | ||
export const login = (username, password) => fetch(`${API_SERVER}/auth/login`, { | ||
method: "POST", | ||
headers: {"Content-Type" : "application/json"}, | ||
body: JSON.stringify({username, password}) | ||
}) | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
jwt.next(data.access_token); | ||
return data.access_token; | ||
}); | ||
|
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