Skip to content

Commit ac18f51

Browse files
feat: auth client setup
1 parent 57d74fe commit ac18f51

File tree

5 files changed

+47
-16
lines changed

5 files changed

+47
-16
lines changed

playground/app.vue

Lines changed: 0 additions & 8 deletions
This file was deleted.

playground/app/app.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script setup lang="ts">
2+
const { signIn } = useUserSession()
3+
4+
async function _login() {
5+
await signIn.username({
6+
username: 'test',
7+
password: 'test',
8+
9+
})
10+
}
11+
</script>
12+
13+
<template>
14+
<div>
15+
Nuxt module playground!
16+
</div>
17+
</template>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { ClientOptions } from 'better-auth'
2+
import { usernameClient, adminClient } from 'better-auth/client/plugins'
3+
4+
export default {
5+
plugins: [
6+
adminClient(),
7+
usernameClient(),
8+
],
9+
} satisfies ClientOptions

playground/nuxt.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export default defineNuxtConfig({
22
modules: ['../src/module'],
33
devtools: { enabled: true },
4-
4+
future: {
5+
compatibilityVersion: 4,
6+
},
57
compatibilityDate: '2025-04-15',
68

79
betterAuth: {

src/templates/useUserSession.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
export async function useUserSession({ options: _ }: any) {
2+
export async function useUserSession({ options }: any) {
33
return [
4-
'import { adminClient, usernameClient } from \'better-auth/client/plugins\'',
54
'import { createAuthClient } from \'better-auth/vue\'',
5+
...options.configs.map((config: any) => {
6+
return `import ${config.key} from "${config.path}"`
7+
}),
68
'import { defu } from \'defu\'',
79
'import { computed, ref } from \'vue\'',
810
'import { navigateTo, useRequestHeaders, useRequestURL, useRuntimeConfig, useState } from \'#app\'',
@@ -16,11 +18,20 @@ export async function useUserSession({ options: _ }: any) {
1618
'',
1719
' const authClient = createAuthClient({',
1820
' baseURL: url.origin,',
19-
' fetchOptions: { headers },',
20-
' plugins: [',
21-
' adminClient(),',
22-
' usernameClient(),',
23-
' ],',
21+
' fetchOptions: {',
22+
...options.configs.map((config: any) => {
23+
return ` ...${config.key}?.fetchOptions || {},`
24+
}),
25+
' headers,',
26+
' },',
27+
...options.configs.map((config: any) => {
28+
return ` ${config.key},`
29+
}),
30+
' plugins: [',
31+
...options.configs.map((config: any) => {
32+
return ` ...${config.key}?.plugins || [],`
33+
}),
34+
' ],',
2435
' })',
2536
'',
2637
' const options = defu(config.public.betterAuth.redirectOptions || {}, {',

0 commit comments

Comments
 (0)