Nuxflare Auth is a modern, lightweight, self-hosted authentication server designed to make adding auth to your apps a breeze. Built with Nuxt 3, Cloudflare Workers, and OpenAuth.js, it bundles everything you need in one place.
A modern, lightweight, self-hosted auth server built with Cloudflare, Nuxt, and OpenAuth.js.
Nuxflare Auth lets you add authentication to your apps without the headache. It's a monorepo that bundles everything you need:
packages/ ├── auth-frontend/ # auth UI components ├── emails/ # react email templates ├── example-client/ # example nuxt client └── functions/ # cloudflare workers
Before getting started, you'll need:
With Nuxt, there are already good auth modules like nuxt-auth-utils and sidebase-auth.
So, what’s different about Nuxflare Auth?
packages/ ├── auth-frontend/ # auth UI components ├── emails/ # react email templates ├── example-client/ # example nuxt client └── functions/ # cloudflare workers
packages/ ├── auth-frontend/ # auth UI components ├── emails/ # react email templates ├── example-client/ # example nuxt client └── functions/ # cloudflare workers
a. Create a Cloudflare API token with the required permissions using this link.
b. Set the CLOUDFLARE_API_TOKEN environment variable:
git clone https://github.com/nuxflare/auth nuxflare-auth cd nuxflare-auth pnpm install
export CLOUDFLARE_API_TOKEN=GahXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# OAuth stuff pnpm sst secret set GoogleClientID your_client_id pnpm sst secret set GoogleClientSecret your_client_secret pnpm sst secret set GithubClientID your_client_id pnpm sst secret set GithubClientSecret your_client_secret # For emails pnpm sst secret set ResendApiKey your_resend_api_key
async run() { const fromEmail = "hi@nuxflare.com"; // ... }
pnpm dev
The repository includes a simple example client app at packages/example-client.
The API for the composables is very similar to nuxt-auth-utils:
pnpm sst deploy --stage production
You should point the client to the endpoint of your deployed auth instance:
```typescript [packages/example-client/app/utils/auth.ts]
const client = createClient({
clientID: "nuxt",
issuer: "https://authdemo.nuxflare.com", // <-- replace this with your endpoint
});
export const useSession = () => { const sessionState = useSessionState(); const accessToken = useAccessTokenCookie(); const refreshToken = useRefreshTokenCookie(); const clear = () => { sessionState.value = {}; accessToken.value = null; refreshToken.value = null; }; return { loggedIn: computed(() => !!sessionState.value.user), user: computed(() => sessionState.value.user || null), session: sessionState, clear, }; };The above is the detailed content of Nuxflare Auth: A lightweight self-hosted auth server built with Nuxt, Cloudflare and OpenAuth.js. For more information, please follow other related articles on the PHP Chinese website!