0.1.1 • Published 9 months ago

auth-ui-vue v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Supabase Auth UI Vue 💚

Supabase Auth UI is a pre-built Vue component for authenticating users. It supports custom themes and extensible styles to match your brand and aesthetic.

This was built as my first step towards contributing to open source and is heavily inspired by Supabase Auth UI React

Demo

You can find a link to the hosted demo here.

Set up Auth UI 👷🏽‍♂️

Import the latest version of supabase-js and the Auth UI package

Using npm:

$ npm install @supabase/supabase-js auth-ui-vue

Using yarn:

$ yarn add @supabase/supabase-js auth-ui-vue

Import the Auth component

Pass supabaseClient from @supabase/supabase-js as a prop to the component.

<script setup lang="ts">
import { createClient } from "@supabase/supabase-js";
import { Auth } from "auth-ui-vue";
import "auth-ui-vue/dist/style.css";

const supabase = createClient("<INSERT PROJECT URL>", "<INSERT PROJECT ANON API KEY>");
</script>

<template>
    <Auth :supabase-client="supabase" />
</template>

This renders the Auth component without any styling. We recommend using one of the predefined themes to style the UI. Import the theme you want to use and pass it to the appearence.theme prop.

<script setup lang="ts">
import { createClient } from "@supabase/supabase-js";
import {
    Auth,
    // Import predefined theme
    ThemeSupa,
} from "auth-ui-vue";
import "auth-ui-vue/dist/style.css";

const supabase = createClient("<INSERT PROJECT URL>", "<INSERT PROJECT ANON API KEY>");
</script>

<template><Auth :supabase-client="supabase" /* Apply predefined theme */ :appearance="{ theme: ThemeSupa }" /></template>

Social Providers 📲

The Auth component also supports login with offical social providers.

<script setup lang="ts">
import { createClient } from "@supabase/supabase-js";
import { Auth, ThemeSupa } from "auth-ui-vue";
import "auth-ui-vue/dist/style.css";

const supabase = createClient("<INSERT PROJECT URL>", "<INSERT PROJECT ANON API KEY>");
</script>

<template>
    <Auth :supabase-client="supabase" :appearance="{ theme: ThemeSupa }" :providers="['google', 'facebook', 'twitter']" />
</template>

Props ⚡️

There are some props that are could be passed to props to the Auth component to determine its output | Prop | Description | Type | default | --- | --- | --- | --- | | supabaseClient | An isomorphic Javascript client for interacting with Postgres. | SupabaseClient | | socialLayout | This determines how the social providers show be displayed | horizontal \| vertical | vertical | | providers | This is an array of social providers that can be used by your users to sign up | Provider[] | | view | This determines what type of auth component is displayed | sign_in \| sign_up \| magic_link \| forgotten_password \| update_password | signin | | redirectTo | This determines where supabase should redirect to when users want to sign in with a magic link, sign in with a social provider or update password | undefined \| string | | onlyThirdPartyProviders | This determines whether to show the email and password mode of authentication when the providers props is set | boolean | false | | magicLink | This determines whether to show the 'Send Magic Link' anchor so users can sign in with magic link | boolean | false | | showLinks | This determines whether to show the links which users can use to change the view to either sign_up/sign_in, magic_link,forgotten_password | boolean | true | | localization | This determines how the auth component texts like label, placeholders, and anchors can be styled to match your design language| Localization | { lang: 'en' } | | appearance | This determines how the auth component can be styled to match your design | Appearance_ | | theme | This determines what variant of the theme passed to appearance.theme | default \| string | default |

External resources for props:

  • Check here to see how to initialise the SupabaseClient.
  • Check here for the list of Providers that can be passed to the providers prop.
  • Check here to see how the language of the auth component can be overwritten using the localization prop.
  • Check here to see how the auth component can be styled to match your design using the appearance prop.

Events 🌐

These are some of the events that are emitted by the Auth component when an auth operation is completed which can be listened to on the page/component where the Auth component is being used.

Event NameDescriptionEmitted Value
set-loadingThis event is emitted when an auth operation begins and when it endsloading: boolean
signin-completedThis event is emitted when the user signs in into your app successfullydata: any
signup-completedThis event is emitted when the user signs up on your app successfullydata:any
magic-link-sentThis event is emitted when the user asks for a magic link to be sent to their email
forgotten-password-completedThis event is emitted when the user wants to reset their password and link to do so is sent to their email
update-password-completedThis event is emitted when the user successfully change their password to a new one

Example:

<script setup lang="ts">
import { createClient } from "@supabase/supabase-js";
import { Auth } from "auth-ui-vue";
import "auth-ui-vue/dist/style.css";

const supabase = createClient("<INSERT PROJECT URL>", "<INSERT PROJECT ANON API KEY>");

function doSomething() {
    alert('Magic Link have being sent to your email.')
}
</script>

<template>
    <Auth 
        :supabase-client="supabase"
        @magic-link-sent="doSomething"
    />
</template>

Customization ✨

There are several ways to customize Auth UI:

Predefined themes

Auth UI comes with several themes to customize the appearance. Each predefined theme comes with at least two variations, a default variation, and a dark variation. You can switch between these themes using the theme prop. Import the theme you want to use and pass it to the appearence.theme prop.

<script setup lang="ts">
import { createClient } from "@supabase/supabase-js";
import {
    Auth,
    // Import predefined theme
    ThemeSupa,
} from "auth-ui-vue";
import "auth-ui-vue/dist/style.css";

const supabase = createClient("<INSERT PROJECT URL>", "<INSERT PROJECT ANON API KEY>");
</script>

<template><Auth :supabase-client="supabase" /* Apply predefined theme */ :appearance="{ theme: ThemeSupa }" /></template>

Currently there is only one predefined theme available, but I plan to add more as soon as Supabase does.

Switch theme variations

Auth UI comes with two theme variations: default and dark. You can switch between these themes with the theme prop.

<script setup lang="ts">
import { createClient } from "@supabase/supabase-js";
import { Auth, ThemeSupa } from "auth-ui-vue";
import "auth-ui-vue/dist/style.css";

const supabase = createClient("<INSERT PROJECT URL>", "<INSERT PROJECT ANON API KEY>");
</script>

<template><Auth :supabase-client="supabase" :appearance="{ theme: ThemeSupa }" /* Set theme to dark */ theme="dark" /></template>

If you don't pass a value to theme it uses the "default" theme. You can pass "dark" to the theme prop to switch to the dark theme. If your theme has other variations, use the name of the variation in this prop.

Override themes

Auth UI themes can be overridden using variable tokens. See the list of variable tokens.

<script setup lang="ts">
import { createClient } from "@supabase/supabase-js";
import { Auth, ThemeSupa } from "auth-ui-vue";
import "auth-ui-vue/dist/style.css";

const supabase = createClient("<INSERT PROJECT URL>", "<INSERT PROJECT ANON API KEY>");
</script>

<template>
    <Auth
        :supabase-client="supabase"
        :appearance="{
            theme: ThemeSupa,
            variables: {
                default: {
                    colors: {
                        brand: 'orange',
                        brandAccent: 'yellow',
                    },
                },
            },
        }"
    />
</template>

If you created your own theme, you may not need to override any of the them.

Create your own theme

You can create your own theme by following the same structure within a appearance.theme property. See the list of tokens within a theme.

<script setup lang="ts">
import { createClient } from "@supabase/supabase-js";
import { Auth } from "auth-ui-vue";
import "auth-ui-vue/dist/style.css"

const supabase = createClient(
  '<INSERT PROJECT URL>',
  '<INSERT PROJECT ANON API KEY>'
)

const customTheme = {
  default: {
    colors: {
      brand: 'hsl(153 60.0% 53.0%)'
      brandAccent: 'hsl(154 54.8% 45.1%)'
      brandButtonText: 'white',
      // ..
    }
  },
  dark: {
    colors: {
      brandButtonText: 'white'
      defaultButtonBackground: '#2e2e2e'
      defaultButtonBackgroundHover: '#3e3e3e'
      //..
    },
  },
  // You can also add more theme variations with different names.
  evenDarker: {
    colors: {
      brandButtonText: 'white',
      defaultButtonBackground: '#1e1e1e',
      defaultButtonBackgroundHover: '#2e2e2e',
      //..
    },
  },
}
</script>

<template><Auth :supabase-client="supabase" theme="default" /* can also be "dark" or "evenDarker" */ :appearance="{ theme: customTheme }" /></template>

You can switch between different variations of your theme with the "theme" prop.

Custom CSS Classes

You can use custom CSS classes for the following elements: "button", "container", "anchor", "divider", "label", "input", "loader", "message".

<script setup lang="ts">
import { createClient } from "@supabase/supabase-js";
import { Auth } from "auth-ui-vue";
import "auth-ui-vue/dist/style.css";

const supabase = createClient("<INSERT PROJECT URL>", "<INSERT PROJECT ANON API KEY>");
</script>

<template>
    <Auth
        :supabase-client="supabase"
        :appearance="{
            className: {
                anchor: 'my-awesome-anchor',
                button: 'my-awesome-button',
                //..
            },
        }"
    />
</template>

Custom inline CSS

You can use custom CSS inline styles for the following elements: "button", "container", "anchor", "divider", "label", "input", "loader", "message".

<script setup lang="ts">
import { createClient } from "@supabase/supabase-js";
import { Auth } from "auth-ui-vue";
import "auth-ui-vue/dist/style.css";

const supabase = createClient("<INSERT PROJECT URL>", "<INSERT PROJECT ANON API KEY>");
</script>

<template>
    <Auth
        :supabase-client="supabase"
        :appearance="{
            style: {
                anchor: { color: 'blue' },
                button: { background: 'red', color: 'white' },
                //..
            },
        }"
    />
</template>

Custom labels

There are currently 5 default localization which can be used with the localization.lang prop. They are en, ja, de_formal, de_informal, pt_br. You can also use custom labels with localization.variables. See the list of labels that can be overwritten.

<script setup lang="ts">
import { createClient } from "@supabase/supabase-js";
import { Auth } from "auth-ui-vue";
import "auth-ui-vue/dist/style.css";

const supabase = createClient("<INSERT PROJECT URL>", "<INSERT PROJECT ANON API KEY>");
</script>

<template>
    <Auth :supabase-client="supabase" /* highlight starts */ :localization="{ variables: { sign_in: { email_label: 'Your email address', password_label: 'Your strong password', },
    } }" /* Highlight ends */ />
</template>
0.1.0

9 months ago

0.1.1

9 months ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago