feat: init new auth

This commit is contained in:
swve 2024-05-25 14:56:28 +02:00
parent f838a8512c
commit 1708b36818
34 changed files with 1853 additions and 3613 deletions

View file

@ -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 = {

View file

@ -1,19 +1,27 @@
import { getAPIUrl } from '@services/config/config'
import { RequestBody, getResponseMetadata } from '@services/utils/ts/requests'
import {
RequestBody,
RequestBodyWithAuthHeader,
getResponseMetadata,
} from '@services/utils/ts/requests'
export async function createInviteCode(org_id: any) {
export async function createInviteCode(org_id: any, access_token: any) {
const result = await fetch(
`${getAPIUrl()}orgs/${org_id}/invites`,
RequestBody('POST', null, null)
RequestBodyWithAuthHeader('POST', null, null, access_token)
)
const res = await getResponseMetadata(result)
return res
}
export async function createInviteCodeWithUserGroup(org_id: any, usergroup_id: number) {
export async function createInviteCodeWithUserGroup(
org_id: any,
usergroup_id: number,
access_token: any
) {
const result = await fetch(
`${getAPIUrl()}orgs/${org_id}/invites_with_usergroups?usergroup_id=${usergroup_id}`,
RequestBody('POST', null, null)
RequestBodyWithAuthHeader('POST', null, null, access_token)
)
const res = await getResponseMetadata(result)
return res
@ -21,11 +29,12 @@ export async function createInviteCodeWithUserGroup(org_id: any, usergroup_id: n
export async function deleteInviteCode(
org_id: any,
org_invite_code_uuid: string
org_invite_code_uuid: string,
access_token: any
) {
const result = await fetch(
`${getAPIUrl()}orgs/${org_id}/invites/${org_invite_code_uuid}`,
RequestBody('DELETE', null, null)
RequestBodyWithAuthHeader('DELETE', null, null, access_token)
)
const res = await getResponseMetadata(result)
return res
@ -33,20 +42,25 @@ export async function deleteInviteCode(
export async function changeSignupMechanism(
org_id: any,
signup_mechanism: string
signup_mechanism: string,
access_token: any
) {
const result = await fetch(
`${getAPIUrl()}orgs/${org_id}/signup_mechanism?signup_mechanism=${signup_mechanism}`,
RequestBody('PUT', null, null)
RequestBodyWithAuthHeader('PUT', null, null, access_token)
)
const res = await getResponseMetadata(result)
return res
}
export async function validateInviteCode(org_id: any, invite_code: string) {
export async function validateInviteCode(
org_id: any,
invite_code: string,
access_token: any
) {
const result = await fetch(
`${getAPIUrl()}orgs/${org_id}/invites/code/${invite_code}`,
RequestBody('GET', null, null)
RequestBodyWithAuthHeader('GET', null, null, access_token)
)
const res = await getResponseMetadata(result)
return res
@ -55,11 +69,12 @@ export async function validateInviteCode(org_id: any, invite_code: string) {
export async function inviteBatchUsers(
org_id: any,
emails: string,
invite_code_uuid: string
invite_code_uuid: string,
access_token: any
) {
const result = await fetch(
`${getAPIUrl()}orgs/${org_id}/invites/users/batch?emails=${emails}&invite_code_uuid=${invite_code_uuid}`,
RequestBody('POST', null, null)
RequestBodyWithAuthHeader('POST', null, null, access_token)
)
const res = await getResponseMetadata(result)
return res