Comments (3)
Just to chime in with an example Login Page I'm using in an app. If a user attempts to hit an authenticated endpoint but is not authenticated, the app will redirect to the login page, but append the original route to the login url, e.g., /login?next=/dashboard?id=1234
. So in the login flow, if the user is successful in authenticating, we redirect them back to the page.
/**
* @/pages/login
*/
import dynamic from 'next/dynamic'
import { NextPage } from 'next'
import { withAuthUser, AuthAction } from 'next-firebase-auth'
import { SimplePageWrapper } from '@/components/layout/PageWrapper'
import FullComponentLoader from '@/components/layout/FullComponentLoader'
const FirebaseAuth = dynamic(() => import('@/components/auth/FirebaseAuth', {
ssr: false,
})
const Login: NextPage = () => (
<SimplePageWrapper title="Login">
<h1>Welcome to My New App!</h1>
<br />
<FirebaseAuth />
</SimplePageWrapper>
)
export default withAuthUser({
whenAuthed: AuthAction.REDIRECT_TO_APP,
whenUnauthedBeforeInit: AuthAction.SHOW_LOADER,
whenUnauthedAfterInit: AuthAction.RENDER,
LoaderComponent: FullComponentLoader,
appPageURL: ({ ctx, AuthUser }) => {
const params =
typeof window === 'undefined'
? new URL(ctx.req.url).searchParams
: new URLSearchParams(window.location.search)
const next = params.get('next')
return next ?? '/dashboard' // return default if no param exists
})(Login)
from next-firebase-auth.
@litewarp That's exactly what I was looking for. If someone else wants to try this out before the stable release, you need the latest alpha to allow appPageURL to accept a function and not just a string.
from next-firebase-auth.
Ahh the dynamic import for the FirebaseAuth
component is a great idea. I will have to try that. I hacked a way to get it not render server side, but this feels much cleaner. Thanks for sharing!
from next-firebase-auth.
Related Issues (20)
- Firebase loads a large iframe.js file but only on mobile HOT 5
- Infinite loop when logging in HOT 3
- getFirebaseAdmin() and onLoginRequestError: () => HOT 1
- -
- Firebase JavaScript SDK 9.17.0 - 9.17.1 - Client side redirect not working. HOT 3
- Firebase client initialization error when using firebase 9.17.1 (latest) HOT 35
- Make the difference between withAuthUserTokenSSR and withAuthUser clearer HOT 2
- Error when deploying to Versel
- Error: Invalid next-firebase-auth options: The "FIREBASE_AUTH_EMULATOR_HOST" environment variable should be the same as the host set in the config
- Add metaData / user data to AuthUser object HOT 4
- Why is databaseURL required during init? HOT 1
- Deploying on Vercel leads to 500 error for ssr-auth-required and ssr-no-token HOT 6
- Infinite rediect to login page when deploy to vercel
- When using 'next dev', two requests are sent to /login or /logout HOT 7
- Auth lost on refresh / navigation, but user stays logged in HOT 1
- firebaseAuthEmulatorHost is ignored and requests to live servers are made HOT 7
- Can I use this library with firebase latest version of firebase. HOT 2
- IdToken not being set as authorization header in axios interceptor on page load.
- Improve setAuthCookies types to no be necessary passing an empty object when not setting the token HOT 1
- Next 14 support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next-firebase-auth.