Code Monkey home page Code Monkey logo

vue-clerk's Introduction

vue-clerk

Vue Clerk is the easiest way to add authentication and user management to your Vue application. Add sign up, sign in, and profile management to your application in minutes.

Warning

This unofficial package isn't connected to Clerk.com. It's a project designed to smoothly incorporate Clerk features into Vue applications.

Installation

npm install vue-clerk

Usage

Vue Clerk requires your application to have the clerkPlugin installed.

If using Vite, set VITE_CLERK_PUBLISHABLE_KEY to your Publishable key in your .env.local file to make the environment variable accessible on process.env and pass it as the publishableKey prop.

<script setup>
import { SignInButton, SignedIn, SignedOut, UserButton } from 'vue-clerk'
</script>

<template>
  <h1>Hello Clerk!</h1>
  <SignedIn>
    <UserButton />
  </SignedIn>
  <SignedOut>
    <SignInButton mode="modal" />
  </SignedOut>
</template>

For further details and examples, please refer to the Documentation.

License

MIT

vue-clerk's People

Contributors

cburgos avatar dependabot[bot] avatar github-actions[bot] avatar jeremy93-2008 avatar nhedger avatar nlaurie avatar renovate[bot] avatar wobsoriano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vue-clerk's Issues

Documentation pages missing or partly hidden

The vue-clerk documentation pages act a bit weird:

  1. If I start on the home page then click on What is Vue Clerk?, both pages display nicely.

  2. If I then reload What is Vue Clerk?, two things happen: (1) the main content for this page disappears and (2) the left 25% of the page is hidden behind the navigation component. See screenshot 1.

  3. When I next use the navigation mention to navigation go to any other documentation page, the main content for each page does appear correctly, but the left 25% of each page is still hidden behind the navigation component. See screenshot 2.

  4. If I then use the navigation menu to go back to the What is Vue Clerk? page, the main content reappears, but the 25% issue remains.

I see exactly the same issues using Firefox, Chrome, or Safari. I'm working on a MacBook Pro running Venutra 13.6.7.

Screenshot 1
Screenshot 2024-06-23 at 3 04 30 pm

Screenshot 2
Screenshot 2024-06-23 at 3 04 21 pm

Usage outside of components?

Hi, is it possible to somehow use the composables outside of vue components / setup functions? Like in other composables / guards etc.? I'm getting a Error: Clerk provider not found when for example trying to get a token to use it in my apollo composable as a bearer token.

Seems like in this context the clerk instance isn't provided under the VUE_CLERK key because vue's provide/inject mechanism doesn't work there. Any workarounds on this? Some other libraries facing this issue have a method to provide the client outside of vue components for this usecase.

For example Vue Apollo has a provideApolloClient method: https://v4.apollo.vuejs.org/guide-composable/setup.html#usage-outside-of-setup

Thanks!

Clerk provider not found

So I was testing vue-clerk in nuxt coz I wanna update the docs to add Nuxt installation guide, but somehow I got this error

Clerk provider not found

Facts:

  • Env is properly loaded
  • No visible installation error

Here's my setup:

// nuxt plugin 
// vue-clerk.client.js

import { defineNuxtPlugin, useRuntimeConfig } from '#imports';
import { clerkPlugin } from 'vue-clerk';

export default defineNuxtPlugin({
	setup (nuxtApp) {
		const runtimeConfig = useRuntimeConfig();
		const clerkPublishableKey = runtimeConfig.public.clerkPublishableKey;
		
		console.log(clerkPublishableKey); // has value
		
		nuxtApp.vueApp.use(clerkPlugin, {
	      	publishableKey: clerkPublishableKey,
	    });
	},
});
// .env

CLERK_PUBLISHABLE_KEY=pk_test_c3dl...Rlax4 # reducted
// nuxt.config.js

...

runtimeConfig: {
 	public: {
    	clerkPublishableKey: process.env.CLERK_PUBLISHABLE_KEY,
  	}, 
},

plugins: [
	'~/plugins/vue-clerk.client.js',
]

...

Screenshot

image

Custom Pages in User Profile for Vue

I would like to implement custom pages in the user profile using Clerk's Vue components, similar to the functionality provided in the React library. Currently, there is documentation and support for this feature in React but not for Vue.

https://clerk.com/docs/components/customization/user-profile

Example Usage:

<UserButton :showName="true" v-if="isSignedIn">
  <UserButton.UserProfilePage url="custom-page" label="Custom Page" :labelIcon="CustomIcon">
    <CustomView />
  </UserButton.UserProfilePage>
</UserButton>

Nuxt.js hash routing error

Have you ever seen this issue

Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#/factor-one' is not a valid selector.

See like there is an issue with the hash routing an nuxt.

However it still logs in , just posts and error in the console and gets reported via sentry.

Incorrect redirection and duplicate OTP emails

Issue
I've integrated vue-clerk into my Vue 3 project to enable email login with OTP. However, when attempting to log in using the email for OTP, the redirection to the "/sign-in/factor-one" page is not being recognized within my Vue router config. As a result, the page goes blank, and the intended component is not displayed.

Solution Attempted
I attempted to address the problem by creating children routes, namely "factor-one","factor-two" and "verify" under the "/sign-in" route. While this resolved the issue of displaying the component that handles OTP entry and allows user access to the application, it introduced a new problem. The OTP email is being sent twice, with the first redirection triggering one and the subsequent component load triggering another.

I would like to know if anyone else has encountered a similar issue and if there are any known solutions or workarounds.

References:
https://clerk.com/blog/remix-delightful-developer-experiences
https://clerk.com/docs/custom-flows/overview

Accessing ClerkProvider

A feature request would be to enable access to ClerkProvider.

It seems using ClerkProvider is the only way to set themes or to customize styling for clerk elements.

Broken callback page after signup attempt

Steps to reproduce:

  1. Signup using Google
  2. Cancel the intent (click the back arrow in the browser)
  3. Redirected to 404 page

The page seems to be broken as it loads to the top of the original Signup page.

Screen.Recording.2023-08-17.at.08.14.43.mov

How to reduce big bundle size?

I just noticed that my app bundle size increased a lot after I installed vue-clerk. I can see that it's caused by @clerk/clerk-js package and not directly by vue-clerk. I saw some commits about experimenting with headless version of clerk but it was reverted after. I would like to ask you what is the state or if you resolved the issue with bundle size somehow different?
Because otherwise this is excellent package and it help me a lot, but this is really a dealbreaker.

Snímek obrazovky 2023-11-07 v 12 00 14

Redirect not working with SignedIn and SignedOut

Description:
I've encountered an issue where the redirect functionality doesn't seem to work when using the SignedIn and SignedOut components. Instead it just displays blank white page.

Steps to Reproduce:

  • Implement SignedIn and SignedOut components in the application.
  • Attempt to trigger a redirect.

Observations:
The redirect does not occur as expected.

Additional Information:
I have tried going through releases and it broke after version 0.3.0

Usage with Nuxt

I am struggling to get the composables to work with Nuxt.

I have tried three approaches:

  1. Following the example from nuxt-clerk-template here: https://github.com/wobsoriano/nuxt-clerk-template/blob/main/plugins/clerk.client.ts
  2. Trying the nuxt-clerk module here: https://github.com/RodrigoProjects/nuxt-clerk (found via this issue: #12)
  3. Going the more vanilla route and following the example of how to integrate a vue plugin with nuxt in conjunction with the vue-clerk docs on using the plugin

I was able to render the auth component and actually login ... but trying to use any composables (ex useUser()) result in the same issue:

  • In the dev server logs: WARN [Vue warn]: injection "VUE_CLERK" not found.
  • The following error in the nuxt error log: This composable can only be used when the Vue Clerk plugin is installed. Learn more: https://vue-clerk.vercel.app/plugin

Here are the two methods attempted in plugins/clerk.client.ts:

Method A:

import { clerkPlugin } from 'vue-clerk/plugin'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(clerkPlugin, {
    publishableKey: import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
  })

  console.log({clerkPlugin, nuxtApp})
  console.log(`Clerk plugin loaded ${import.meta.env.VITE_CLERK_PUBLISHABLE_KEY}`)
})

Method B:

import { Clerk, provideClerkToVueApp } from 'vue-clerk/plugin'

export default defineNuxtPlugin(async (nuxtApp) => {
  const isClerkLoaded = ref(false)

  const clerk = new Clerk(import.meta.env.VITE_CLERK_PUBLISHABLE_KEY)
  console.log(`Clerk plugin loaded ${import.meta.env.VITE_CLERK_PUBLISHABLE_KEY}`)

  // Instead of using the `vue-clerk` plugin, we can use this internal function to create a Clerk instance.
  provideClerkToVueApp(nuxtApp.vueApp, clerk, {
    isClerkLoaded,
    shouldLoadClerk: false,
    clerkOptions: {}, // Optional since we run `clerk.load` manually
  })

  // This will make sure that the clerk library is loaded in the client first before moving on to the next middleware.
  await clerk.load({
    routerPush: (to) => {
      return navigateTo(to)
    },
    routerReplace: (to) => {
      return navigateTo(to, { replace: true })
    },
  })

  isClerkLoaded.value = true

  return {
    provide: {
      clerk
    },
  }
})

Any insights would be greatly appreciated, thank you.

Upgrading from 0.1.7 to 0.3.7 breaks local development

Upgrading from 0.1.7 to 0.3.7 breaks local development: The clerk client on locahost keeps issuing gets and posts to clerk servers at a high pace until eventually we get a 429 back.

Failed to load resource: the server responded with a status of 429 ()

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/ci.yml
.github/workflows/release.yml
npm
package.json
  • @clerk/shared ^2.4.5
  • @clerk/types ^4.12.1
playground/package.json

  • Check this box to trigger a request for Renovate to run again on this repository

Vue v2.x

What are my options with Vue2.x?

UserButton stops showing user full name

The only thing I did since it was working is bumped nuxt. Currently it is 3.12.4 and there is no full name next to the avatar button (ofc :show-name="true" is there).

useUser() computed properties undefined on initial page load

Hi, I have the following component.

<template>
  <div>
    Projects
    <div v-if="isSignedIn">
      <div v-for="project in data" :key="project.project.id">
        {{ project.project.name }} create by {{ project.user.email }}
      </div>
    </div>
  </div>
</template>

<script setup>
import { useUser } from "vue-clerk";
const { isSignedIn, user } = await useUser();
console.log(isSignedIn.value, user.value);

const { data } = await useFetch("/api/database/projects/usersProjects", {
  query: { userId: user?.value?.id },
});
</script>

When hit refresh in the browser, the user value is undefined and so my useFetch call fails. If I click navigate to another component and then click navigate back to this component, the user variable has a value and the useFetch call works correctly.

I assume vue-clerk is contacting clerk to get an auth token when the page renders hence the values being undefined at that point.

How can I work around this issue.

Chat application using Vue-Clerk failed in offline environment.

Hey, I am building a chat application in PWA.
I have a situation that user may check the message in offline environment.

When I switch the network off, the clerkjs couldn't initialize properly.
截圖 2023-12-07 上午11 32 53

I came out a feature that user can set a fallback option, when he/she try to get access to the application with previous clerkjs data.

This feature may may use localStorage or IndexedDB to save the state in browser, and keep watching the network status.
Once the network is online, updating the state immediately.

watcher on useOrganization fires several times

when watching the ref inside the useOrganization composable, or the valie.id directly, the ord switcher will cause the watcher to fire off several times. It seems as if the org id gets set correctly -> set as null -> set correctly very quickly:

image
const { organization, isLoaded } = useOrganization();
watch(organization, (newValue, oldValue) => {
  console.log(
    "newValue",
    newValue,
    "oldValue",
    oldValue,
    "isLoaded",
    isLoaded.value
  );
});

isLoaded goes to false as the org changes back to null

reading values like isSignedIn etc on page load returnes undefined.

i might be doing something wong, but after looking at other implementations i can't figure out what that may be.

The issue is that when trying to read values on page load or onMounted() clerk will be undefined:

<script setup lang="ts">
import { useAuth } from 'vue-clerk';

const { isSignedIn } = useAuth();

console.log(isSignedIn.value); // undefined
</script>

if this is the normal behavior how are you supposed to implement routegards then?

Reactivity issue?

It seems I have reactivity issues. Excuse me if it is not intended by design.

Have a container component with "OrganizationSwitcher" component inside. It switches the organizations perfectly well, but it does not provide any events on changes.

In another component I just want to listen to current organization switch changes.

In Component 2:

const { organization } = useClerk();

this "organization" is not reactive.

I don`t know how to listen to changes. Computed props or deep watches are not triggering.
DOM element listening sound stupid. only SetInterval allows to get the up to date info.

const clerk = useClerk();

setInterval(() => {
   if (clerk?.organization) {
   ...do whatever with update
  }
}, 1000);

Maybe I don't understand it well.

Thanks for package and efforts.

Upgraded to 0.4.0 and I no longer get the isLoaded or isSignedIn changes

When upgrading to latest all of my code watching these references is no longer seeing any changes in clerk.

In my pinia store I have a
clerk.addListener((emission) => {
log.debug(emission | user: ${emission.user?.id});
});

and it is correctly firing an event when the cached login authenticates. but on the SignIn form

const { isLoaded, isSignedIn } = useAuth();

isLoaded remains false and isSignedIn is undefined. They never change.
The only difference in my code is the upgrade to 0.4.0 .
This is a plain Vue application.

I also upgraded my nuxtjs website with this version and it seems to be working as expected.

I also added
clerk.addOnLoaded(()=> {
log.debug(addOnLoaded);
})

and this is firing the callback as expected

Inconsistent behavior in auth middleware in Nuxt

Thank you for this contribution to the JS / Vue community!

I'm observing some strange behavior and wondering if it might be an issue. It could be that it's working properly and I just don't understand the intended function.

It seems like the first time I load vue-clerk / useClerk after warming up my Nuxt dev server, it functions as expected -- on the client side, clerk.loaded is true and clerk.user is defined. However, with every subsequent page load, clerk.loaded will be false and clerk.user will be undefined. Is this expected?

I'm seeing this behavior in the https://github.com/wobsoriano/nuxt-clerk-template repo. My only changes are to add my keys to .env and to add some logs to console in the middleware/auth.ts:

  // On client, check if clerk is loaded and log to console
  if (process.client) {
    if (clerk.loaded)
      console.log('Clerk loaded!');
    else
      console.log('Clerk not loaded!');
    console.log('Clerk user:', clerk.user)
  }

How do I use useUser on the server side

Thanks for this library I love that I can now use Clerk in Nuxt.

My only issue at the moment is that I am only able to access the Clerk user on the front end with useUser.

When I use a useFetch to pull data from the backend, I need to be able to access user direct from Clerk so I can verify the user before sending data back to the front end.

With the following code, I get the error This composable can only be used when the Vue Clerk plugin is installed

import { useUser } from 'vue-clerk'
export default defineEventHandler(async (event) => {
  const user = useUser()
   console.log("clerk user", user)
})

Update: I notice from another issue that is now closed a user was told that vue-clerk only works on the client. If this is the case how do we secure a backend in nuxt. I can not trust the front end to send a userId to the backend, that could be faked by a malicious actor.

I am assuming I am missing something here that other people have already solved, but how do I get secure access to the clerk user on the backend?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.