-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First. * already snippets for that * cleanup * auth_svc_admin * Auth, not auth-next * Express stub should not be in snippet * Move import into snippet * Update firebaseserverapp.js
- Loading branch information
1 parent
e74e8fd
commit a9160f6
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// @ts-nocheck | ||
// [START serverapp_auth] | ||
import { initializeServerApp } from 'firebase/app'; | ||
import { getAuth } from 'firebase/auth'; | ||
import { headers } from 'next/headers'; | ||
import { redirect } from 'next/navigation'; | ||
|
||
export default function MyServerComponent() { | ||
|
||
// Get relevant request headers (in Next.JS) | ||
const authIdToken = headers().get('Authorization')?.split('Bearer ')[1]; | ||
|
||
// Initialize the FirebaseServerApp instance. | ||
const serverApp = initializeServerApp(firebaseConfig, { authIdToken }); | ||
|
||
// Initialize Firebase Authentication using the FirebaseServerApp instance. | ||
const auth = getAuth(serverApp); | ||
|
||
if (auth.currentUser) { | ||
redirect('/profile'); | ||
} | ||
|
||
// ... | ||
} | ||
// [END serverapp_auth] | ||
|
||
const firebaseConfig = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "firebaseserverapp-next", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" | ||
}, | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"firebase": "^10.0.0", | ||
"next": "^14.1.3" | ||
} | ||
} |