fix oauth
This commit is contained in:
parent
42a4ae0c6c
commit
33bf78ecc3
|
@ -34,3 +34,17 @@ export const getLoginByGoogle = (locale: string, accesstoken: string): Promise<{
|
|||
},
|
||||
locale
|
||||
});
|
||||
|
||||
export const getRegisterByApple = (locale: string, code: string): Promise<{ jwtToken: string }> => apiRequest({
|
||||
url: '/auth/registerexternalappleweb',
|
||||
method: 'post',
|
||||
data: { code },
|
||||
locale
|
||||
});
|
||||
|
||||
export const getLoginByApple = (locale: string, code: string): Promise<{ jwtToken: string }> => apiRequest({
|
||||
url: '/auth/tryloginexternalappleweb',
|
||||
method: 'post',
|
||||
data: { code },
|
||||
locale
|
||||
});
|
||||
|
|
|
@ -13,7 +13,6 @@ export async function createCheckoutSession(
|
|||
const ui_mode = data.get(
|
||||
"uiMode",
|
||||
) as Stripe.Checkout.SessionCreateParams.UiMode;
|
||||
console.log('DATA', data)
|
||||
const origin: string = headers().get("origin") as string;
|
||||
|
||||
const checkoutSession: Stripe.Checkout.Session =
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
'use client'
|
||||
|
||||
import React from 'react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { apiClient } from '../../../lib/apiClient';
|
||||
|
||||
export default function BbAppleLogIn() {
|
||||
|
||||
const urlParams = new URLSearchParams(location.search);
|
||||
var code = urlParams.getAll('code')[0];
|
||||
const ref = useRef(false);
|
||||
|
||||
var makeRequest = async (c) => {
|
||||
|
||||
if(ref.current) {
|
||||
return;
|
||||
}
|
||||
ref.current = true;
|
||||
|
||||
try {
|
||||
var result = await apiClient.post('http://192.168.0.106:5090/api/auth/registerexternalappleweb', {
|
||||
code: c
|
||||
});
|
||||
localStorage.setItem('bbuddy_token_test', result.data.jwtToken);
|
||||
window.location.href="/";
|
||||
}
|
||||
catch (err) {
|
||||
/*process*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
makeRequest(code);
|
||||
},[code]);
|
||||
return (
|
||||
<>
|
||||
</>
|
||||
);
|
||||
};
|
|
@ -1,40 +0,0 @@
|
|||
'use client'
|
||||
|
||||
import React from 'react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { apiClient } from '../../../lib/apiClient';
|
||||
|
||||
export default function BbAppleLogIn() {
|
||||
|
||||
const urlParams = new URLSearchParams(location.search);
|
||||
var code = urlParams.getAll('code')[0];
|
||||
const ref = useRef(false);
|
||||
|
||||
var makeRequest = async (c) => {
|
||||
|
||||
if(ref.current) {
|
||||
return;
|
||||
}
|
||||
ref.current = true;
|
||||
|
||||
try {
|
||||
var result = await apiClient.post('http://192.168.0.106:5090/api/auth/tryloginexternalappleweb', {
|
||||
code: c
|
||||
});
|
||||
localStorage.setItem('bbuddy_token_test', result.data.jwtToken);
|
||||
window.location.href="/";
|
||||
}
|
||||
catch (err) {
|
||||
/*process*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
makeRequest(code);
|
||||
},[code]);
|
||||
return (
|
||||
<>
|
||||
</>
|
||||
);
|
||||
};
|
|
@ -50,7 +50,6 @@ function renderWidget (widget: Widget, index: number) {
|
|||
|
||||
export default async function BlogItem({params}: { params: BlogPostPageParams }) {
|
||||
const item = await fetchBlogPost({slug: params.slug, preview: draftMode().isEnabled })
|
||||
console.log('BLOG POST')
|
||||
console.log(Util.inspect(item, {showHidden: false, depth: null, colors: true}))
|
||||
if (!item) notFound();
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
'use client'
|
||||
|
||||
import React, { useEffect } from 'react';
|
||||
import { notification } from 'antd';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { CustomSpin } from '../../../../components/view/CustomSpin';
|
||||
import { getLoginByApple } from '../../../../actions/auth';
|
||||
import { getUserData } from '../../../../actions/profile';
|
||||
import { AUTH_TOKEN_KEY, AUTH_USER } from '../../../../constants/common';
|
||||
import { useLocalStorage } from '../../../../hooks/useLocalStorage';
|
||||
import { useRouter } from '../../../../navigation';
|
||||
|
||||
export default function AppleLoginPage({ params: { locale } }: { params: { locale: string } }) {
|
||||
const params = useSearchParams();
|
||||
const router = useRouter();
|
||||
const [, setToken] = useLocalStorage(AUTH_TOKEN_KEY, '');
|
||||
|
||||
useEffect(() => {
|
||||
const code = params.get('code');
|
||||
if (code) {
|
||||
getLoginByApple(locale, code)
|
||||
.then((data) => {
|
||||
if (data.jwtToken) {
|
||||
getUserData(locale, data.jwtToken)
|
||||
.then((profile) => {
|
||||
localStorage.setItem(AUTH_USER, JSON.stringify(profile));
|
||||
setToken(data.jwtToken);
|
||||
})
|
||||
} else {
|
||||
notification.error({
|
||||
message: 'Error',
|
||||
description: 'Access denied'
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
const err = error?.message ? JSON.parse(error.message) : {};
|
||||
notification.error({
|
||||
message: 'Error',
|
||||
description: err?.details?.errMessage || undefined
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
router.push('/');
|
||||
});
|
||||
}
|
||||
}, [params]);
|
||||
|
||||
return <CustomSpin />;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
'use client'
|
||||
|
||||
import React, { useEffect } from 'react';
|
||||
import { notification } from 'antd';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { CustomSpin } from '../../../../components/view/CustomSpin';
|
||||
import { getRegisterByApple } from '../../../../actions/auth';
|
||||
import { getUserData } from '../../../../actions/profile';
|
||||
import { AUTH_TOKEN_KEY, AUTH_USER } from '../../../../constants/common';
|
||||
import { useLocalStorage } from "../../../../hooks/useLocalStorage";
|
||||
import { useRouter } from '../../../../navigation';
|
||||
|
||||
export default function AppleRegisterPage({ params: { locale } }: { params: { locale: string } }) {
|
||||
const params = useSearchParams();
|
||||
const router = useRouter();
|
||||
const [, setToken] = useLocalStorage(AUTH_TOKEN_KEY, '');
|
||||
|
||||
useEffect(() => {
|
||||
const code = params.get('code');
|
||||
if (code) {
|
||||
getRegisterByApple(locale, code)
|
||||
.then((data) => {
|
||||
if (data.jwtToken) {
|
||||
getUserData(locale, data.jwtToken)
|
||||
.then((profile) => {
|
||||
localStorage.setItem(AUTH_USER, JSON.stringify(profile));
|
||||
setToken(data.jwtToken);
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
const err = error?.message ? JSON.parse(error.message) : {};
|
||||
notification.error({
|
||||
message: 'Error',
|
||||
description: err?.details?.errMessage || undefined
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
router.push('/');
|
||||
});
|
||||
}
|
||||
}, [params]);
|
||||
|
||||
return <CustomSpin />;
|
||||
}
|
|
@ -1,12 +1,16 @@
|
|||
'use client';
|
||||
|
||||
import React, { Dispatch, FC, SetStateAction, useEffect } from 'react';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { usePathname, useSearchParams } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
import { Modal, Form } from 'antd';
|
||||
import { Modal, Form, notification } from 'antd';
|
||||
import { CloseOutlined } from '@ant-design/icons';
|
||||
import { RegisterContent, ResetContent, FinishContent, EnterContent } from './authModalContent';
|
||||
import { i18nText } from '../../i18nKeys';
|
||||
import { useRouter } from '../../navigation';
|
||||
import { AUTH_USER} from '../../constants/common';
|
||||
import { getRegisterByApple, getLoginByApple } from '../../actions/auth';
|
||||
import { getUserData } from '../../actions/profile';
|
||||
|
||||
type AuthModalProps = {
|
||||
open: boolean;
|
||||
|
@ -27,6 +31,47 @@ export const AuthModal: FC<AuthModalProps> = ({
|
|||
}) => {
|
||||
const [form] = Form.useForm<{ login: string, password: string, confirmPassword: string }>();
|
||||
const paths = usePathname().split('/');
|
||||
const params = useSearchParams();
|
||||
const router = useRouter();
|
||||
|
||||
const onUpdateToken = (token: string) => {
|
||||
if (updateToken && typeof updateToken !== 'string') {
|
||||
updateToken(token);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const code = params.get('code');
|
||||
const type = params.get('state');
|
||||
if (code && type) {
|
||||
const appleFunc = type === 'bbregister' ? getRegisterByApple : getLoginByApple;
|
||||
appleFunc(locale, code)
|
||||
.then((data) => {
|
||||
if (data.jwtToken) {
|
||||
getUserData(locale, data.jwtToken)
|
||||
.then((profile) => {
|
||||
localStorage.setItem(AUTH_USER, JSON.stringify(profile));
|
||||
onUpdateToken(data.jwtToken);
|
||||
})
|
||||
} else {
|
||||
notification.error({
|
||||
message: 'Error',
|
||||
description: 'Access denied'
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
const err = error?.message ? JSON.parse(error.message) : {};
|
||||
notification.error({
|
||||
message: 'Error',
|
||||
description: err?.details?.errMessage || undefined
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
router.push('/');
|
||||
});
|
||||
}
|
||||
}, [params]);
|
||||
|
||||
const onAfterClose = () => {
|
||||
form.resetFields();
|
||||
|
@ -38,12 +83,6 @@ export const AuthModal: FC<AuthModalProps> = ({
|
|||
}
|
||||
}, [mode]);
|
||||
|
||||
const onUpdateToken = (token: string) => {
|
||||
if (updateToken && typeof updateToken !== 'string') {
|
||||
updateToken(token);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
className="b-modal"
|
||||
|
|
|
@ -76,7 +76,6 @@ export const ScheduleModal: FC<ScheduleModalProps> = ({
|
|||
getSchedulerSession(parseData as SignupSessionData, locale || 'en', jwt)
|
||||
.then((session) => {
|
||||
setSessionId(session?.sessionId);
|
||||
console.log(session?.sessionId);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import React, { FC, useState } from 'react';
|
||||
import { Form, FormInstance, notification } from 'antd';
|
||||
import Image from 'next/image';
|
||||
import { useGoogleLogin } from '@react-oauth/google';
|
||||
import AppleLogin from 'react-apple-login';
|
||||
import { AUTH_USER } from '../../../constants/common';
|
||||
import { getAuth, getLoginByGoogle } from '../../../actions/auth';
|
||||
import { getUserData } from '../../../actions/profile';
|
||||
|
@ -10,8 +12,6 @@ import { FilledButton } from '../../view/FilledButton';
|
|||
import { OutlinedButton } from '../../view/OutlinedButton';
|
||||
import { LinkButton } from '../../view/LinkButton';
|
||||
import { i18nText } from '../../../i18nKeys';
|
||||
import { useGoogleLogin } from '@react-oauth/google';
|
||||
import AppleLogin from 'react-apple-login'
|
||||
|
||||
type EnterProps = {
|
||||
form: FormInstance;
|
||||
|
@ -76,6 +76,11 @@ export const EnterContent: FC<EnterProps> = ({
|
|||
updateToken(data.jwtToken);
|
||||
handleCancel();
|
||||
})
|
||||
} else {
|
||||
notification.error({
|
||||
message: 'Error',
|
||||
description: 'Access denied'
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
|
@ -148,6 +153,7 @@ export const EnterContent: FC<EnterProps> = ({
|
|||
<AppleLogin
|
||||
clientId="bbuddy.expert"
|
||||
redirectURI="https://bbuddy.expert"
|
||||
state="bblogin"
|
||||
responseType="code"
|
||||
responseMode="query"
|
||||
render={({ onClick }) => (
|
||||
|
|
|
@ -2,6 +2,7 @@ import React, { FC, useState } from 'react';
|
|||
import { Form, FormInstance, notification } from 'antd';
|
||||
import Image from 'next/image';
|
||||
import { useGoogleLogin } from '@react-oauth/google';
|
||||
import AppleLogin from 'react-apple-login';
|
||||
import { AUTH_USER } from '../../../constants/common';
|
||||
import { getRegister, getRegisterByGoogle } from '../../../actions/auth';
|
||||
import { getUserData, setPersonData } from '../../../actions/profile';
|
||||
|
@ -10,7 +11,6 @@ import { CustomInputPassword } from '../../view/CustomInputPassword';
|
|||
import { FilledButton } from '../../view/FilledButton';
|
||||
import { OutlinedButton } from '../../view/OutlinedButton';
|
||||
import { i18nText } from '../../../i18nKeys';
|
||||
import AppleLogin from 'react-apple-login';
|
||||
|
||||
type RegisterProps = {
|
||||
form: FormInstance;
|
||||
|
@ -169,6 +169,7 @@ export const RegisterContent: FC<RegisterProps> = ({
|
|||
<AppleLogin
|
||||
clientId="bbuddy.expert"
|
||||
redirectURI="https://bbuddy.expert"
|
||||
state="bbregister"
|
||||
responseType="code"
|
||||
responseMode="query"
|
||||
render={({ onClick }) => (
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
|
||||
import React, { FC, useState, useEffect } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Button } from 'antd';
|
||||
import { useSelectedLayoutSegment } from 'next/navigation';
|
||||
import { Link } from '../../../navigation';
|
||||
|
|
Loading…
Reference in New Issue