sidebase / nuxt-auth-example Goto Github PK
View Code? Open in Web Editor NEWA example application using nuxt-auth.
Home Page: https://nuxt-auth-example.sidebase.io
A example application using nuxt-auth.
Home Page: https://nuxt-auth-example.sidebase.io
Some features exist that are not yet part of the demo:
getToken
signIn('github')
or signIn('credentials', {username: 'a', password: 'b'})
These should be show-cased as well.
Polishing:
@sidebase/[email protected]
[1]: bar that flickers when logged in:
No response
No response
No response
I'm using:
auth: {
provider: {
type: 'authjs'
},
globalAppMiddleware: true
}
in nuxt.config.ts
Which means that it enables the default auth middleware:
import { navigateTo, defineNuxtRouteMiddleware, useRuntimeConfig } from "#app";
import { determineCallbackUrl } from "../utils/url.mjs";
import { useAuth } from "#imports";
export default defineNuxtRouteMiddleware((to) => {
const metaAuth = typeof to.meta.auth === "object" ? {
unauthenticatedOnly: true,
...to.meta.auth
} : to.meta.auth;
if (metaAuth === false) {
return;
}
const authConfig = useRuntimeConfig().public.auth;
const { status, signIn } = useAuth();
const isGuestMode = typeof metaAuth === "object" && metaAuth.unauthenticatedOnly;
if (isGuestMode && status.value === "unauthenticated") {
return;
}
if (typeof metaAuth === "object" && !metaAuth.unauthenticatedOnly) {
return;
}
if (status.value === "authenticated") {
if (isGuestMode) {
return navigateTo(metaAuth.navigateAuthenticatedTo ?? "/");
}
return;
}
if (authConfig.globalAppMiddleware.allow404WithoutAuth) {
const matchedRoute = to.matched.length > 0;
if (!matchedRoute) {
return;
}
}
if (authConfig.provider.type === "authjs") {
const signInOptions = { error: "SessionRequired", callbackUrl: determineCallbackUrl(authConfig, () => to.path) };
return signIn(void 0, signInOptions);
} else if (typeof metaAuth === "object" && metaAuth.navigateUnauthenticatedTo) {
return navigateTo(metaAuth.navigateUnauthenticatedTo);
} else {
return navigateTo(authConfig.provider.pages.login);
}
});
But as you can see there is no "process.server" check before running "signIn" method. And as shown in documentation: https://next-auth.js.org/getting-started/client#signin
this method is client side only.
This causes this error: [nuxt] [request error] [unhandled] [500] Cannot set headers after they are sent to the client
No response
No response
No response
No response
After deploying https://nuxt-auth-example.sidebase.io we noticed that the initial loading time is very high. This issue is to track down the reason and fix it, or add a loading indicator for when the page has not loaded yet.
No response
No response
Hello. Please fill in with an example file .env.example
I can't figure out how to fill it out correctly.
No response
In sidebase/nuxt-auth#96 we added a custom signin page to the nuxt-auth
playground. It might be helpful for developers to also see a preview of this in the nuxt-auth-example
.
No response
how to protect login page from being accessed when user is already authenticated? or probably this should added as a feature?
No response
Darwin
v16.13.0
3.3.2
2.3.2
[email protected]
vite
css
, modules
, auth
@nuxtjs/[email protected]
, @sidebase/[email protected]
-
git clone [email protected]:sidebase/nuxt-auth-example.git
cd nuxt-auth-example
echo 'shamefully-hoist=true' > .npmrc
echo 'auto-install-peers=true' >> .npmrc
pnpm install
pnpm run build
NUXT_SECRET=a-secret AUTH_ORIGIN=https://b-website.com ORIGIN=https://a-website.com PORT=3003 node .output/server/index.mjs
In another terminal
curl -v localhost:3003/protected/globally
#...
< HTTP/1.1 302 Found
< set-cookie: __Host-next-auth.csrf-token=f41225f307a199b55bf3244d9b0a7c2b2f3ac83297ced3117cf9f9e5b4826d80%7C47d8fb2dc0f16eab6150b67f8cc61ad6557d179d0b87174e8827612891457aff; Path=/; HttpOnly; Secure; SameSite=Lax,__Secure-next-auth.callback-url=https%3A%2F%2Fb-website.com; Path=/; HttpOnly; Secure; SameSite=Lax
< location: /api/auth/signin?callbackUrl=%2Fprotected%2Fglobally
# ...
<
* Connection #0 to host localhost left intact
<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=/api/auth/signin?callbackUrl=%2Fprotected%2Fglobally"></head></html>%
You can see that its using the __Secure-next-auth.callback-url=https%3A%2F%2Fb-website.com;
b-website
ORIGIN
in docs but the framework wants AUTH_ORIGIN
. So you can see from the reproduction I have to add both.This has caused a fair bit of confusion as I'm trying to implement nuxt-auth.
I'm also curious why sometimes I've seen it redirect to an absolute path, and other times its a relative path. π€
No response
RootDir: /workspace/nuxt-auth-example 09:47:21
Nuxt project info: 09:47:21
Linux
v16.19.0
3.1.2
2.1.2
[email protected]
vite
css
, modules
, auth
@nuxtjs/[email protected]
, @sidebase/[email protected]
-
https://github.com/sidebase/nuxt-auth-example.git
open the source code with Gitpod, export env varible, and npm run start. when login get error as "This page isnβt working" which url is "https://sidebase-nuxtauthexampl-6cxmiofy627.ws-us88.gitpod.io/api/auth/callback/credentials"
Request URL: https://sidebase-nuxtauthexampl-6cxmiofy627.ws-us88.gitpod.io/api/auth/callback/credentials
Request Method: POST
Status Code: 502
Remote Address: 127.0.0.1:1080
Referrer Policy: strict-origin-when-cross-origin
No response
No response
my env is :
#GITHUB_CLIENT_SECRET
NUXT_SECRET="feijign_random_string"
ORIGIN=http://121.5.146.136:3000/
is I must to config the CERTBOT_DOMAIN?
No response
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.