mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: init new auth
This commit is contained in:
parent
f838a8512c
commit
1708b36818
34 changed files with 1853 additions and 3613 deletions
|
|
@ -10,8 +10,8 @@ interface LoginAndGetTokenResponse {
|
|||
// TODO : everything in this file need to be refactored including security issues fix
|
||||
|
||||
export async function loginAndGetToken(
|
||||
username: string,
|
||||
password: string
|
||||
username: any,
|
||||
password: any
|
||||
): Promise<any> {
|
||||
// Request Config
|
||||
|
||||
|
|
@ -37,6 +37,37 @@ export async function loginAndGetToken(
|
|||
return response
|
||||
}
|
||||
|
||||
export async function loginWithOAuthToken(
|
||||
email: any,
|
||||
provider: any,
|
||||
accessToken: string
|
||||
): Promise<any> {
|
||||
// Request Config
|
||||
|
||||
// get origin
|
||||
const HeadersConfig = new Headers({
|
||||
'Content-Type': 'application/json',
|
||||
})
|
||||
const body = {
|
||||
email: email,
|
||||
provider: provider,
|
||||
access_token: accessToken,
|
||||
}
|
||||
const jsonBody = JSON.stringify(body);
|
||||
|
||||
const requestOptions: any = {
|
||||
method: 'POST',
|
||||
headers: HeadersConfig,
|
||||
body: jsonBody,
|
||||
redirect: 'follow',
|
||||
credentials: 'include',
|
||||
}
|
||||
|
||||
// fetch using await and async
|
||||
const response = await fetch(`${getAPIUrl()}auth/oauth`, requestOptions)
|
||||
return response
|
||||
}
|
||||
|
||||
export async function sendResetLink(email: string, org_id: number) {
|
||||
const result = await fetch(
|
||||
`${getAPIUrl()}users/reset_password/send_reset_code/${email}?org_id=${org_id}`,
|
||||
|
|
@ -102,10 +133,8 @@ export async function getUserInfo(token: string): Promise<any> {
|
|||
}
|
||||
|
||||
export async function getUserSession(token: string): Promise<any> {
|
||||
const origin = window.location.origin
|
||||
const HeadersConfig = new Headers({
|
||||
Authorization: `Bearer ${token}`,
|
||||
Origin: origin,
|
||||
})
|
||||
|
||||
const requestOptions: any = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue