-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement basic authentication between next and express
- Loading branch information
1 parent
74561ee
commit f6dd75d
Showing
14 changed files
with
582 additions
and
157 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,52 @@ | ||
import axios from "axios"; | ||
|
||
// Client API functions that communicate with the API server | ||
|
||
// Axios config | ||
const api = axios.create({ | ||
baseURL: `http://${process.env.NEXT_PUBLIC_API_SERVER_URL}:${process.env.NEXT_PUBLIC_API_SERVER_PORT}`, | ||
withCredentials: true, | ||
timeout: 2000, //Timeout response after 2 seconds | ||
}); | ||
|
||
/* Auth Functions */ | ||
|
||
export async function login(email, password) { | ||
const response = await api.post("/api/auth/login", {email: email, password: password}); | ||
return response.data; | ||
} | ||
|
||
export async function register(username, email, password) { | ||
const response = await api.post("/api/auth/register", {username: username, email: email, password: password}); | ||
return response.data; | ||
} | ||
|
||
export async function logout() { | ||
const response = await api.post("/api/auth/logout"); | ||
return response.data; | ||
import fetch from "node-fetch"; | ||
|
||
class Api { | ||
constructor() { | ||
this._api = axios.create({ | ||
baseURL: `http://${process.env.NEXT_PUBLIC_API_SERVER_URL}:${process.env.NEXT_PUBLIC_API_SERVER_PORT}`, | ||
withCredentials: true, | ||
timeout: 2000 //Timeout response after 2 seconds | ||
}); | ||
} | ||
|
||
get api() { | ||
return this._api; | ||
} | ||
|
||
async login(email, password) { | ||
const response = await this.api.post("/api/auth/login", { email: email, password: password }); | ||
return response.data; | ||
} | ||
|
||
async register(username, email, password) { | ||
const response = await this.api.post("/api/auth/register", { | ||
username: username, | ||
email: email, | ||
password: password | ||
}); | ||
return response.data; | ||
} | ||
|
||
async logout() { | ||
const response = await this.api.post("/api/auth/logout"); | ||
return response.data; | ||
} | ||
|
||
async getProfilePic(userid) { | ||
const response = await this.api.get(`/api/users/${userid}/profilepic`, { responseType: "blob" }); | ||
return response.data; | ||
} | ||
|
||
async checkAuth(req) { | ||
const response = await fetch("http://localhost:5000/api/auth/checkAuth", { | ||
method: "POST", | ||
headers: req.headers | ||
}); | ||
const data = await response.json(); | ||
return data; | ||
} | ||
} | ||
|
||
/* User functions */ | ||
|
||
export async function getProfilePic(userid) { | ||
const response = await api.get(`/api/users/${userid}/profilepic`, {responseType: 'blob'}); | ||
return response.data; | ||
} | ||
const jasmaApi = new Api(); | ||
export default jasmaApi; |
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.