Nuxt / Vue
.env
NUXT_PUBLIC_WAITLISTLY_PUBLIC_KEY=pk_your_public_key
NUXT_WAITLISTLY_SECRET_KEY=sk_your_secret_keynuxt.config.ts
export default defineNuxtConfig({
runtimeConfig: {
waitlistlySecretKey: '', // NUXT_WAITLISTLY_SECRET_KEY
public: { waitlistlyPublicKey: '' }, // NUXT_PUBLIC_WAITLISTLY_PUBLIC_KEY
},
});Collect
components/WaitlistForm.vue
<script setup lang="ts">
const config = useRuntimeConfig();
const route = useRoute();
const email = ref('');
const result = ref<any>(null);
async function join() {
result.value = await $fetch('https://waitlistly.live/api/v1/contacts', {
method: 'POST',
headers: { 'X-Waitlistly-Key': config.public.waitlistlyPublicKey },
body: { email: email.value, ref: route.query.ref },
});
}
</script>
<template>
<p v-if="result?.status === 'joined'">You're #{{ result.position }}. Share {{ result.referral_link }}</p>
<form v-else @submit.prevent="join">
<input v-model="email" type="email" required />
<button>Join the waitlist</button>
</form>
</template>Gate and activate
server/api/signup.post.ts
export default defineEventHandler(async (event) => {
const { inviteCode } = await readBody(event);
const { waitlistlySecretKey } = useRuntimeConfig();
const call = (path: string, body: unknown) =>
$fetch<any>(`https://waitlistly.live/api/v1/${path}`, { method: 'POST', headers: { Authorization: `Bearer ${waitlistlySecretKey}` }, body });
const invite = await call('invites/verify', { code: inviteCode });
if (!invite.valid) throw createError({ statusCode: 403, message: 'This invite is not valid or has expired.' });
// …create the account…
await call('activations', { code: inviteCode });
return { ok: true };
});Last updated on