Just making a mess mostly I think
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
'use client';
|
||||
import { signInWithApple } from '@/lib/actions';
|
||||
import { signInWithApple, getProfile, updateProfile } from '@/lib/actions';
|
||||
import { StatusMessage, SubmitButton } from '@/components/default';
|
||||
import { useAuth } from '@/components/context';
|
||||
import { useRouter } from 'next/navigation';
|
||||
@ -34,8 +34,23 @@ export const SignInWithApple = ({
|
||||
const result = await signInWithApple();
|
||||
|
||||
if (result?.success && result.data) {
|
||||
const profileResponse = await getProfile();
|
||||
if (profileResponse.success) {
|
||||
const profile = profileResponse.data;
|
||||
if (!profile.provider) {
|
||||
const updateResponse = await updateProfile({
|
||||
provider: result.data.provider,
|
||||
})
|
||||
if (!updateResponse.success) throw new Error('Could not update provider!');
|
||||
} else {
|
||||
const updateResponse = await updateProfile({
|
||||
provider: profile.provider + ' ' + result.data.provider,
|
||||
})
|
||||
if (!updateResponse.success) throw new Error('Could not update provider!');
|
||||
}
|
||||
}
|
||||
// Redirect to Apple OAuth page
|
||||
window.location.href = result.data;
|
||||
window.location.href = result.data.url;
|
||||
} else {
|
||||
setStatusMessage(`Error signing in with Apple!`);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import Image from 'next/image';
|
||||
import { type buttonVariants } from '@/components/ui';
|
||||
import { type ComponentProps } from 'react';
|
||||
import { type VariantProps } from 'class-variance-authority';
|
||||
import { getProfile, updateProfile } from '@/lib/hooks';
|
||||
|
||||
type SignInWithMicrosoftProps = {
|
||||
className?: ComponentProps<'div'>['className'];
|
||||
@ -32,8 +33,22 @@ export const SignInWithMicrosoft = ({
|
||||
const result = await signInWithMicrosoft();
|
||||
|
||||
if (result?.success && result.data) {
|
||||
// Redirect to Microsoft OAuth page
|
||||
window.location.href = result.data;
|
||||
const profileResponse = await getProfile();
|
||||
if (profileResponse.success) {
|
||||
const profile = profileResponse.data;
|
||||
if (!profile.provider) {
|
||||
const updateResponse = await updateProfile({
|
||||
provider: result.data.provider,
|
||||
})
|
||||
if (!updateResponse.success) throw new Error('Could not update provider!');
|
||||
} else {
|
||||
const updateResponse = await updateProfile({
|
||||
provider: profile.provider + ' ' + result.data.provider,
|
||||
})
|
||||
if (!updateResponse.success) throw new Error('Could not update provider!');
|
||||
}
|
||||
}
|
||||
window.location.href = result.data.url;
|
||||
} else {
|
||||
setStatusMessage(`Error: Could not sign in with Microsoft!`);
|
||||
}
|
||||
|
Reference in New Issue
Block a user