Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Oct 16, 2023
1 parent 95cccd6 commit 0d81954
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/pages/Oauth/AuthForm/AuthFormField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { LoginFlowUiNode } from '@kybernetwork/oauth2'
import React from 'react'

interface AuthFormFieldProps extends React.InputHTMLAttributes<HTMLInputElement> {
field: LoginFlowUiNode
outline?: boolean
}

const AuthFormField: React.FC<AuthFormFieldProps> = ({ field }) => {
const attributes = field.attributes
if (field.group === 'oidc') return null
return <input type={attributes.type} value={attributes.value} name={attributes.name} />
}
export default AuthFormField
41 changes: 40 additions & 1 deletion src/pages/Oauth/AuthForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { LoginFlow, LoginMethod } from '@kybernetwork/oauth2'
import { LoginFlow, LoginFlowUiNode, LoginMethod } from '@kybernetwork/oauth2'
import axios from 'axios'
import React, { Fragment, useMemo } from 'react'
import { Flex } from 'rebass'
import styled from 'styled-components'

import useTheme from 'hooks/useTheme'
import AuthFormField from 'pages/Oauth/AuthForm/AuthFormField'
import ButtonEth from 'pages/Oauth/AuthForm/ButtonEth'
import ButtonGoogle from 'pages/Oauth/AuthForm/ButtonGoogle'
import EmailLoginForm from 'pages/Oauth/AuthForm/EmailLoginForm'
Expand Down Expand Up @@ -66,9 +68,46 @@ const AuthForm: React.FC<AuthFormProps> = ({ formConfig, signInWithEth, flowStat

if (!formConfig) return null
const { ui } = formConfig
const test = async () => {
try {
const data = new FormData()
const data2 = {
email: 'danh.nguyen@kyber.network',
}
let csrf = ''
ui?.nodes.forEach(el => {
if (el.attributes.name === 'password' || el.attributes.name === 'identifier' || el.attributes.name === 'method')
return
if (el.attributes.name === 'csrf_token') {
csrf = el.attributes.value
}
// data.append(el.attributes.name, el.attributes.value)
// data2[el.attributes.name as any] = el.attributes.value
})
const resp = await axios.post(
// 'https://identity-api.dev.kyberengineering.io/self-service/login/email/codes?flow=' +
// queryStringToObject(window.location.search).flow,
ui.action.replace('/login', '/login/email/codes'),
data2,
{
withCredentials: true,
headers: {
'X-CSRF-Token': csrf,
},
},
)
console.log(123, resp)
} catch (error) {
console.log(123, error)
}
}
return (
<Form encType="application/x-www-form-urlencoded" action={ui.action} method={ui.method}>
<div onClick={test}>test</div>
<AuthFormFieldMessage messages={ui.messages} />
{ui?.nodes?.map((field: LoginFlowUiNode, index: number) => (
<AuthFormField key={index} field={field} />
))}
{nodes.map((el, i) => (
<Fragment key={i}>
{el}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Oauth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function Login() {
throw new Error('Not found login method for this app')
}
if (isIncludeGoogle) {
autoLoginMethod = LoginMethod.GOOGLE
// autoLoginMethod = LoginMethod.GOOGLE
}
}
if (canAutoSignInEth(loginMethods)) {
Expand Down

0 comments on commit 0d81954

Please sign in to comment.