-
-
Notifications
You must be signed in to change notification settings - Fork 224
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
6 changed files
with
82 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function get_api_server(): string { | ||
console.log('API_SERVER:', process.env.NEXT_PUBLIC_API_SERVER); | ||
return process.env.NEXT_PUBLIC_API_SERVER || ''; | ||
}; |
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,27 @@ | ||
import { get_api_server } from '@/api/env'; | ||
|
||
export async function login(username: string, password: string): Promise<boolean> { | ||
// combine username and password into a single string and use Base64 encoding | ||
const credentials = `${username}:${password}`; | ||
const encodedCredentials = btoa(credentials); | ||
|
||
// make a GET request to the /api/auth endpoint via basic authentication | ||
const resp = await fetch(get_api_server() + '/api/v1/auth', { | ||
method: 'GET', | ||
headers: { | ||
'Authorization': `Basic ${encodedCredentials}` | ||
} | ||
}) | ||
|
||
if (resp.status === 200) { | ||
// store the credentials in local storage | ||
localStorage.setItem('credentials', encodedCredentials); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
export async function logout(): Promise<void> { | ||
localStorage.removeItem('credentials'); | ||
} |
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