fix: avoid invite logout
This commit is contained in:
@@ -16,16 +16,18 @@ export const load = async ({ params = { hash: '' } }) => {
|
||||
|
||||
const { orgId, email, orgSiteName } = JSON.parse(hashData);
|
||||
|
||||
const _currentOrg = await getCurrentOrg(orgSiteName, true);
|
||||
const currentOrg = await getCurrentOrg(orgSiteName, true);
|
||||
|
||||
const profile = await getProfile(email);
|
||||
console.log('profile data', profile);
|
||||
|
||||
return {
|
||||
orgId,
|
||||
email,
|
||||
currentOrg: _currentOrg,
|
||||
profile
|
||||
invite: {
|
||||
orgId,
|
||||
email,
|
||||
currentOrg,
|
||||
profile
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error decoding invite params.hash', error);
|
||||
|
||||
@@ -48,12 +48,12 @@
|
||||
|
||||
try {
|
||||
loading = true;
|
||||
let profile: Profile | null = data.profile;
|
||||
let profile: Profile | null = data.invite.profile;
|
||||
|
||||
if (!data.profile) {
|
||||
if (!data.invite.profile) {
|
||||
// Signup
|
||||
const { data: signupData, error } = await supabase.auth.signUp({
|
||||
email: data.email,
|
||||
email: data.invite.email,
|
||||
password: fields.password
|
||||
});
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
id: userId,
|
||||
username: fields.name.toLowerCase().replace(' ', '-') + new Date().getTime(),
|
||||
fullname: fields.name,
|
||||
email: data.email
|
||||
email: data.invite.email
|
||||
})
|
||||
.select();
|
||||
|
||||
@@ -96,12 +96,12 @@
|
||||
verified: true,
|
||||
profile_id: profile.id
|
||||
})
|
||||
.match({ email: data.email, organization_id: data.currentOrg?.id });
|
||||
.match({ email: data.invite.email, organization_id: data.invite.currentOrg?.id });
|
||||
|
||||
console.log('Update member response', updateMemberRes);
|
||||
|
||||
const res = await supabase.auth.signInWithPassword({
|
||||
email: data.email,
|
||||
email: data.invite.email,
|
||||
password: fields.password
|
||||
});
|
||||
|
||||
@@ -110,6 +110,8 @@
|
||||
}
|
||||
|
||||
formRef?.reset();
|
||||
|
||||
console.log({ path: $currentOrgPath });
|
||||
return goto($currentOrgPath);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
@@ -124,20 +126,26 @@
|
||||
|
||||
function setCurOrg(cOrg: CurrentOrg) {
|
||||
if (!cOrg) return;
|
||||
|
||||
console.log(cOrg);
|
||||
currentOrg.set(cOrg);
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
setTheme(data.currentOrg?.theme || '');
|
||||
onMount(async () => {
|
||||
await logout(false);
|
||||
|
||||
logout(false);
|
||||
setTheme(data.invite.currentOrg?.theme || '');
|
||||
|
||||
setCurOrg(data.invite.currentOrg as CurrentOrg);
|
||||
});
|
||||
|
||||
$: errors.confirmPassword = getConfirmPasswordError(fields);
|
||||
$: disableSubmit = getDisableSubmit(fields);
|
||||
|
||||
$: setCurOrg(data.currentOrg as CurrentOrg);
|
||||
$: console.log('data.profile', data.profile);
|
||||
$: console.log('data', data.invite);
|
||||
|
||||
$: console.log('org', $currentOrg);
|
||||
$: console.log('path', $currentOrgPath);
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -147,7 +155,7 @@
|
||||
<AuthUI {supabase} isLogin={false} {handleSubmit} isLoading={loading} showLogo={true} bind:formRef>
|
||||
<div class="mt-4 w-full">
|
||||
<p class="dark:text-white text-lg font-semibold mb-6">
|
||||
{#if data.profile}
|
||||
{#if data.invite.profile}
|
||||
Log in to join
|
||||
{:else}
|
||||
Create a free account to join
|
||||
@@ -155,14 +163,14 @@
|
||||
</p>
|
||||
<TextField
|
||||
label="Your Email"
|
||||
value={data.email}
|
||||
value={data.invite.email}
|
||||
type="email"
|
||||
placeholder="you@domain.com"
|
||||
className="mb-6"
|
||||
inputClassName="w-full"
|
||||
isDisabled={true}
|
||||
/>
|
||||
{#if !data.profile}
|
||||
{#if !data.invite.profile}
|
||||
<TextField
|
||||
label="Full Name"
|
||||
bind:value={fields.name}
|
||||
@@ -188,7 +196,7 @@
|
||||
helperMessage="Password must be more than 6 characters"
|
||||
isRequired
|
||||
/>
|
||||
{#if !data.profile}
|
||||
{#if !data.invite.profile}
|
||||
<TextField
|
||||
label="Confirm Password"
|
||||
bind:value={fields.confirmPassword}
|
||||
|
||||
Reference in New Issue
Block a user