feat: hackathon
This commit is contained in:
@@ -1,29 +1,10 @@
|
||||
import { TVerifyOtpRequest, usePostVerifyEmail } from '@imphnen-frontend-service/service';
|
||||
import { toast } from 'sonner';
|
||||
import { useNavigate, useSearchParams } from 'react-router';
|
||||
|
||||
// OTP verification is not used with GitHub OAuth authentication
|
||||
// This hook is kept for backward compatibility but is not used
|
||||
export const useOtp = () => {
|
||||
const navigate = useNavigate();
|
||||
const { mutate, isPending } = usePostVerifyEmail();
|
||||
const [ searchParams ] = useSearchParams();
|
||||
|
||||
const otp = (payload: TVerifyOtpRequest) => {
|
||||
mutate({ ...payload, email: searchParams.get("email") || "" }, {
|
||||
onSuccess: (data) => {
|
||||
toast.success('Berhasil Registrasi');
|
||||
navigate("/auth/register/success");
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(
|
||||
err?.response?.data?.message ??
|
||||
'Terjadi Kesalahan yang tidak diketahui'
|
||||
);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
otp,
|
||||
isLoading: isPending,
|
||||
otp: () => {
|
||||
console.warn('OTP verification is not used with GitHub OAuth authentication');
|
||||
},
|
||||
isLoading: false,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,28 +1,10 @@
|
||||
import { TRegisterRequest, usePostRegister } from '@imphnen-frontend-service/service';
|
||||
import { toast } from 'sonner';
|
||||
import { useNavigate } from 'react-router';
|
||||
|
||||
// Registration is handled through GitHub OAuth
|
||||
// This hook is kept for backward compatibility but is not used
|
||||
export const useRegister = () => {
|
||||
const navigate = useNavigate();
|
||||
const { mutate, isPending } = usePostRegister();
|
||||
|
||||
const register = (payload: TRegisterRequest) => {
|
||||
mutate(payload, {
|
||||
onSuccess: (data) => {
|
||||
toast.success('Berhasil Registrasi');
|
||||
navigate(`/auth/register/otp?email=${payload.email}`);
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(
|
||||
err?.response?.data?.message ??
|
||||
'Terjadi Kesalahan yang tidak diketahui'
|
||||
);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
register,
|
||||
isLoading: isPending,
|
||||
register: () => {
|
||||
console.warn('Registration is handled through GitHub OAuth');
|
||||
},
|
||||
isLoading: false,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,25 +1,10 @@
|
||||
import { TSendOTPRequest, usePostSendOTP } from '@imphnen-frontend-service/service';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
// OTP is not used with GitHub OAuth authentication
|
||||
// This hook is kept for backward compatibility but is not used
|
||||
export const useSendOTP = () => {
|
||||
const { mutate, isPending } = usePostSendOTP();
|
||||
|
||||
const resendOTP = (payload: TSendOTPRequest) => {
|
||||
mutate(payload, {
|
||||
onSuccess: (data) => {
|
||||
toast.success('Berhasil Mengirim Ulang OTP');
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(
|
||||
err?.response?.data?.message ??
|
||||
'Terjadi Kesalahan yang tidak diketahui'
|
||||
);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
resendOTP,
|
||||
isLoading: isPending,
|
||||
resendOTP: () => {
|
||||
console.warn('OTP is not used with GitHub OAuth authentication');
|
||||
},
|
||||
isLoading: false,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,41 +1,21 @@
|
||||
import { TLoginRequest, usePostLogin } from '@imphnen-frontend-service/service';
|
||||
import { supabase } from '@imphnen-frontend-service/service';
|
||||
import { useAuthStore } from './';
|
||||
import { toast } from 'sonner';
|
||||
import { useNavigate } from 'react-router';
|
||||
|
||||
export const useSession = () => {
|
||||
const navigate = useNavigate();
|
||||
const { mutate, isPending } = usePostLogin();
|
||||
const { setLoading, setSession, clearSession, session, status } =
|
||||
useAuthStore();
|
||||
const { clearSession, session, status } = useAuthStore();
|
||||
const isAuthenticated = status === 'authenticated';
|
||||
|
||||
const signIn = (payload: TLoginRequest) => {
|
||||
setLoading(true);
|
||||
mutate(payload, {
|
||||
onSuccess: (data) => {
|
||||
toast.success('Login sukses');
|
||||
setSession(data.data);
|
||||
navigate(0);
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(
|
||||
err?.response?.data?.message ??
|
||||
'Terjadi Kesalahan yang tidak diketahui'
|
||||
);
|
||||
clearSession();
|
||||
},
|
||||
});
|
||||
};
|
||||
const signOut = () => {
|
||||
const signOut = async () => {
|
||||
await supabase.auth.signOut();
|
||||
clearSession();
|
||||
navigate(0);
|
||||
navigate('/auth/login');
|
||||
};
|
||||
|
||||
return {
|
||||
session,
|
||||
signIn,
|
||||
signOut,
|
||||
isLoading: isPending,
|
||||
isAuthenticated,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -23,6 +23,9 @@ type TUserItem = {
|
||||
is_active: boolean;
|
||||
phone_number: string;
|
||||
role: TRoleItem;
|
||||
bio?: string;
|
||||
location?: string;
|
||||
skills?: string[];
|
||||
};
|
||||
|
||||
export const SessionUser = {
|
||||
|
||||
Reference in New Issue
Block a user