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

chore(examples): add authenticated-routes example using firebase #3669

Merged
merged 15 commits into from
Mar 6, 2025

Conversation

downright-development
Copy link
Contributor

I struggled greatly getting firebase client-side authentication to play nicely inside TSR. This is a quick example on setting up your project. In this example, I'm using firebase oauth with Github. :) For this example you work you MUST create a firebase project and setup github oauth.

I personally prefer using the directory format below for organizational reasons, but I left it flat to align with other demos.

_auth/
protected-route-1 (dashboard)
(public)/
login.tsx
other public routes like signup

Due to conflicts with AuthProvider being a type in firebase, I've updated the context to "AuthContextProvider" in this example

The index.tsx in this example is a great place to host your sales/landing page... if a user is logged in and attempts to hit the root index, they'll get routed back to /dashboard, otherwise they can directly route to index OR the /login page.

@downright-development
Copy link
Contributor Author

A MAJOR requirement is to setup your .env.local with the following variables for Firebase.

VITE_PUBLIC_FIREBASE_API_KEY=
VITE_PUBLIC_FIREBASE_AUTH_DOMAIN=
VITE_PUBLIC_FIREBASE_PROJECT_ID=
VITE_PUBLIC_FIREBASE_STORAGE_BUCKET=
VITE_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=
VITE_PUBLIC_FIREBASE_APP_ID=

@downright-development
Copy link
Contributor Author

Update - I realized Zustand wasn't actually necessary. Resolved to remove zustand dependency!

@SeanCassiere SeanCassiere self-requested a review March 5, 2025 18:29
Copy link

nx-cloud bot commented Mar 5, 2025

View your CI Pipeline Execution ↗ for commit e495d04.

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 5m 48s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 2m 29s View ↗

☁️ Nx Cloud last updated this comment at 2025-03-06 07:22:00 UTC

Copy link

pkg-pr-new bot commented Mar 6, 2025

Open in Stackblitz

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@3669

@tanstack/create-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/create-router@3669

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@3669

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@3669

@tanstack/create-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/create-start@3669

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@3669

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@3669

@tanstack/react-router-with-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-with-query@3669

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@3669

@tanstack/react-start-api-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-api-routes@3669

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@3669

@tanstack/react-start-config

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-config@3669

@tanstack/react-start-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-plugin@3669

@tanstack/react-start-router-manifest

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-router-manifest@3669

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@3669

@tanstack/react-start-server-functions-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server-functions-client@3669

@tanstack/react-start-server-functions-fetcher

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server-functions-fetcher@3669

@tanstack/react-start-server-functions-handler

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server-functions-handler@3669

@tanstack/react-start-server-functions-ssr

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server-functions-ssr@3669

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@3669

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@3669

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@3669

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@3669

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@3669

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@3669

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@3669

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@3669

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@3669

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@3669

@tanstack/solid-start-api-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-api-routes@3669

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@3669

@tanstack/solid-start-config

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-config@3669

@tanstack/solid-start-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-plugin@3669

@tanstack/solid-start-router-manifest

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-router-manifest@3669

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@3669

@tanstack/solid-start-server-functions-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server-functions-client@3669

@tanstack/solid-start-server-functions-fetcher

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server-functions-fetcher@3669

@tanstack/solid-start-server-functions-handler

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server-functions-handler@3669

@tanstack/solid-start-server-functions-ssr

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server-functions-ssr@3669

@tanstack/start-config

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-config@3669

@tanstack/start

npm i https://pkg.pr.new/TanStack/router/@tanstack/start@3669

@tanstack/start-server-functions-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-server@3669

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@3669

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@3669

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@3669

commit: e495d04

@SeanCassiere
Copy link
Member

Looking at the test failure, it looks like you might want to add a src/vite.d.ts file with all the environment variables.

/// <reference types="vite/client" />

interface ImportMetaEnv {
  readonly VITE_CUSTOM_ENV_VARIABLE: string
}

interface ImportMeta {
  readonly env: ImportMetaEnv
}

@SeanCassiere SeanCassiere changed the title Functional example of firebase client-side auth and protected routes. chore(examples): add authenticated-routes example using firebase Mar 6, 2025
@SeanCassiere SeanCassiere merged commit d20088e into TanStack:main Mar 6, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants