Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Migrate to @supabase/ssr #357

Merged
merged 26 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
74624c1
refactor: migrate to @supabase/ssr
felixgabler Apr 27, 2024
6123971
refactor: use clientOptions from @supabase/ssr by default
felixgabler Apr 27, 2024
4dcea96
fix: use h3 getCookie instead of useCookie in server plugin
felixgabler Apr 27, 2024
cdde49f
chore: update supabase-js to fix warning
felixgabler Apr 27, 2024
60384af
refactor: fix tsc & lint issues
felixgabler Apr 27, 2024
b768da8
fix: unwrap proxy object from cookie to enable message posting
felixgabler Apr 28, 2024
7f468d3
refactor(composables): useSupabaseuser and useSupabaseSession async
larbish Apr 30, 2024
1b0209b
fix(lint): useless import
larbish Apr 30, 2024
988c9a5
chore(app): remove logs
larbish Apr 30, 2024
e5062b1
refactor: fix ts errors
felixgabler Apr 30, 2024
b4b6975
fix(serverSupabaseUser): getuser instead of getSession
larbish May 2, 2024
f05024c
chore(module): optimize cookie dep
larbish May 2, 2024
660b811
Merge branch 'main' into pr/357
larbish May 2, 2024
3fd5784
Merge branch 'main' into pr/357
larbish May 13, 2024
c9a73b9
chore(deps): upgrade
larbish May 13, 2024
7a3199c
chore(deps): upgrade
larbish May 17, 2024
f7cbc2f
fix(user): populate only once in plugin
larbish May 17, 2024
4dc3828
refactor(user): simplify auth state change handler
felixgabler May 17, 2024
714dbc4
refactor(user): transform useSupabaseUser back to non-async
felixgabler May 17, 2024
b45770c
refactor: clean up cache handling of server composables
felixgabler May 17, 2024
0895ccc
refactor(session): remove async from useSupabaseSession and manage th…
felixgabler May 17, 2024
9cd48ff
fix: do not modify headers after they have been sent
felixgabler May 18, 2024
92bf923
Merge pull request #1 from felixgabler/fg/plugin_controlled_session
felixgabler May 21, 2024
72e2120
chore: update @supabase/ssr to pre-release version
felixgabler Jun 13, 2024
e2878b4
chore: upgrade @supabase/ssr to 0.4.0
felixgabler Jun 24, 2024
830161c
refactor: fix lint issue
felixgabler Jun 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/components/AppHeader.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
const client = useSupabaseClient()
const user = useSupabaseUser()
const user = await useSupabaseUser()
const colorMode = useColorMode()

const toggleDark = () => {
Expand Down
2 changes: 1 addition & 1 deletion demo/pages/confirm.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
const user = useSupabaseUser()
const user = await useSupabaseUser()

watch(user, () => {
if (user.value) {
Expand Down
2 changes: 1 addition & 1 deletion demo/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
const user = useSupabaseUser()
const user = await useSupabaseUser()
const { auth } = useSupabaseClient()

const redirectTo = `${useRuntimeConfig().public.baseUrl}/confirm`
Expand Down
2 changes: 1 addition & 1 deletion demo/pages/tasks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { Database } from '~~/types/database.types'

const client = useSupabaseClient<Database>()
const user = useSupabaseUser()
const user = await useSupabaseUser()

const tasksFromServer = ref()
const isModalOpen = ref(false)
Expand Down
17 changes: 11 additions & 6 deletions docs/content/2.get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Default:

Default: `sb`

Cookie name used for storing access and refresh tokens, added in front of `-access-token` and `-refresh-token` to form the full cookie name e.g. `sb-access-token`
Cookie name used for storing the redirect path when using the `redirect` option, added in front of `-redirect-path` to form the full cookie name e.g. `sb-redirect-path`

### cookieOptions

Expand All @@ -115,20 +115,25 @@ Options for cookies used to share tokens between server and client, refer to [co

### `clientOptions`

Default:
Default:

```ts
clientOptions: { }
```

Supabase client options [available here](https://supabase.com/docs/reference/javascript/initializing#parameters) merged with default values from `@supabase/ssr`:

```ts
clientOptions: {
auth: {
flowType: 'pkce',
detectSessionInUrl: true,
persistSession: true,
autoRefreshToken: true
autoRefreshToken: isBrowser(),
detectSessionInUrl: isBrowser(),
persistSession: true,
},
}
```

Supabase client options [available here](https://supabase.com/docs/reference/javascript/initializing#parameters).

## Versions

Expand Down
4 changes: 2 additions & 2 deletions docs/content/3.authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The redirect URL must be configured in your Supabase dashboard under `Authentica

```vue [pages/confirm.vue]
<script setup lang="ts">
const user = useSupabaseUser()
const user = await useSupabaseUser()

watch(user, () => {
if (user.value) {
Expand All @@ -87,7 +87,7 @@ You must enable the `cookieRedirect` option of the [redirectOptions](/get-starte

```vue [pages/confirm.vue]
<script setup lang="ts">
const user = useSupabaseUser()
const user = await useSupabaseUser()

// Get redirect path from cookies
const cookieName = useRuntimeConfig().public.supabase.cookieName
Expand Down
4 changes: 2 additions & 2 deletions docs/content/4.usage/composables/useSupabaseUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Once logged in, you can [auto-import](https://nuxt.com/docs/guide/directory-stru

```vue
<script setup>
const user = useSupabaseUser()
const user = await useSupabaseUser()
</script>
```

Expand All @@ -21,7 +21,7 @@ If the [redirect](/get-started#redirect) option is disabled, you can protect you

```ts [middleware/auth.ts]
export default defineNuxtRouteMiddleware((to, _from) => {
const user = useSupabaseUser()
const user = await useSupabaseUser()

if (!user.value) {
return navigateTo('/login')
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@
},
"dependencies": {
"@nuxt/kit": "^3.11.2",
"@supabase/supabase-js": "2.43.0",
"@supabase/ssr": "^0.3.0",
"@supabase/supabase-js": "2.43.2",
"defu": "^6.1.4",
"pathe": "^1.1.2"
},
"devDependencies": {
"@nuxt/eslint": "^0.3.10",
"@nuxt/eslint": "^0.3.12",
"@nuxt/module-builder": "^0.6.0",
"@nuxt/schema": "^3.11.2",
"@release-it/conventional-changelog": "^8.0.1",
"@types/node": "^20.12.8",
"eslint": "^9.1.1",
"@types/node": "^20.12.12",
"eslint": "^9.2.0",
"nuxt": "^3.11.2",
"prettier": "^3.2.5",
"release-it": "^17.2.1",
Expand Down
2 changes: 1 addition & 1 deletion playground/pages/confirm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (import.meta.server) {
)
}

const user = useSupabaseUser()
const user = await useSupabaseUser()
watch(user, () => {
if (user.value) {
return navigateTo('/user')
Expand Down
2 changes: 1 addition & 1 deletion playground/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { Database } from '~~/types/database.types'

const supabase = useSupabaseClient<Database>()
const user = useSupabaseUser()
const user = await useSupabaseUser()

const { data } = useAsyncData(async () => {
// const { data } = await supabase.from('test').select('*')
Expand Down
2 changes: 1 addition & 1 deletion playground/pages/login.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- eslint-disable no-console -->
<script setup lang="ts">
const supabase = useSupabaseClient()
const user = useSupabaseUser()
const user = await useSupabaseUser()

watchEffect(() => {
// Can be uncommented in next nuxt version when https://github.com/nuxt/nuxt/issues/21841 is fixed
Expand Down
2 changes: 1 addition & 1 deletion playground/pages/protected.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
</template>

<script setup lang="ts">
const session = useSupabaseSession()
const session = await useSupabaseSession()
</script>
4 changes: 2 additions & 2 deletions playground/pages/user.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!-- eslint-disable no-console -->
<script setup lang="ts">
const supabase = useSupabaseClient()
const user = useSupabaseUser()
const user = await useSupabaseUser()
const router = useRouter()
const session = useSupabaseSession()
const session = await useSupabaseSession()

if (import.meta.server) {
console.log('User on server side: ', user.value?.email)
Expand Down
Loading
Loading