#auth

1 messages · Page 1 of 1 (latest)

grizzled trellis
#

Hello there,
I am new to Discord and astrojs.
I have been struggling with the astro auth example: https://github.com/osadavc/astro-auth-example
When using the Google provider, the app does log in; however, the callbackURL (https://youtu.be/dQw4w9WgXcQ) is ignored.
When I replace the YouTube callbackURL with, say, '/dashboard', and create a 'dashboard.astro' page, it still logs in, but shows the homepage (http://localhost:3000).
When I replace the YouTube callbackURL with 'http://localhost:3000/api/auth/oauth/google', and create an 'api/auth/oauth/google.astro' page, it logs in, and correctly displays the 'api/auth/oauth/google.astro' page.

How to make it show the 'dashboard.astro' page upon log in?

GitHub

Contribute to osadavc/astro-auth-example development by creating an account on GitHub.

The official video for “Never Gonna Give You Up” by Rick Astley
Taken from the album ‘Whenever You Need Somebody’ – deluxe 2CD and digital deluxe out 6th May 2022 Pre-order here – https://RickAstley.lnk.to/WYNS2022ID

“Never Gonna Give You Up” was a global smash on its release in July 1987, topping the charts in 25 countries including Rick’s nat...

▶ Play video
tired kayak
#

u meant page not redirecting ?

grizzled trellis
tired kayak
#

structure should go like

/
├── public/
├── src/
│   └── pages/
│         └── api/
│   └── index.astro
└── package.json
grizzled trellis
tired kayak
#

u are using google oauth r?

grizzled trellis
grizzled trellis
#

Well, I added a redirectURL to Main.jsx:

#

<button
onClick={() => {
signIn({
provider: "google",
callbackURL: "/dashboard",// https://youtu.be/dQw4w9WgXcQ
});
}}
>
Sign In
</button>

The official video for “Never Gonna Give You Up” by Rick Astley
Taken from the album ‘Whenever You Need Somebody’ – deluxe 2CD and digital deluxe out 6th May 2022 Pre-order here – https://RickAstley.lnk.to/WYNS2022ID

“Never Gonna Give You Up” was a global smash on its release in July 1987, topping the charts in 25 countries including Rick’s nat...

▶ Play video
tired kayak
#

wait lemme test it

grizzled trellis
tired kayak
#

are you in SSR r?

#

then why don't you try
astro.redirect()
when you finished logging in ?

#

instead of callback ?

#

@grizzled trellis

grizzled trellis
#

yes, using SSR. And yes, I could probably use astro.redirect(), or maybe redirectUser, the @astro-auth/core method. However, shouldn't callbackURL work in SSR too?

tired kayak
#

how about this ?
<button
onClick={() => {
signIn({
callbackURL: "/dashboard",
provider: "google",
});
}}
>
Sign In
</button>

grizzled trellis
#

yes, it logs in, but redirects to the homepage, for some reason 🤔

#

I think I'll try Next Auth, see if the behaviour is Google related or not. And as a workaround, I could still redirect with astro or astro auth...

tired kayak
#

page should be in pages folder
not in api ?

grizzled trellis
#

yes

grizzled trellis
#

I tried a sample project with NextAuth, using the same Google Cloud API config (same Google credential): it works, Google log in can redirect to the 'protected' page. So my issue with astro auth is not Google-related 🤔

grizzled trellis
#

@tired kayak To make it work with astro auth, I ended up using the work around you mentioned:

#

import { getUser, redirectUser } from "@astro-auth/core";
const user = getUser({ client: Astro });
if (user) {
return redirectUser("/dashboard");
}

#

@tired kayak thank you for your time 👍

stray echo
cosmic bolt
#

Astro Auth isn't actively maintained anymore (afaik). I'd recommend something like Lucia-auth as a newer, maintained alternative

stray echo
cosmic bolt
# stray echo Thanks for suggesting Lucia-auth . I will go check it out. BTW, just out of cur...

Hopefully. I created a PR at the beginning of the year, but it was a bad time, as things were still changing fast, and it couldn't be merged. auth-astro is the unofficial package in the meantime. I'm in the process of rewriting auth-astro for Astro v4 (coming out next week), but it does work in v3 until then, albeit with some minor issues. Hopefully, once authjs is stable enough, we can look at getting an official package merged houston_laugh