[Question] What happens in createRouteHandler
Bulletninja opened this issue · 1 comments
auth-email/auth-email/src-app/api/index.ts
Line 220 in 9dc57ce
i'm trying to understand some parts of your code, but i'm not sure what that auth
method does, specially this expression:
handlers[key as keyof typeof handlers]
An explanation of this would be very much appreciated.
~~Also, does nextjs wrap query params into a params object? ~~
I'm trying to implement a simple auth for learning purposes, and in my case i'm using netlify lambdas, and i get the token directly.
Was also curious that your example uses #token=
instead of ?token=
. But perhaps that should be a separate question.
Thanks again for this library btw.
PS: Read more about nextjs server side and found those params basically serve as routers.
The createAuthRouteHandler
function creates a handler which handles all requests to /api/auth/...
.
You see this object here, which defines some keys:
auth-email/auth-email/src-app/api/index.ts
Lines 203 to 215 in 9dc57ce
The handlers[key as keyof typeof handlers]
is typescripts way of accessing handlers[key]
. So we answer requests to /api/auth/login
with the handler defined in the object above under the login
key.
Was also curious that your example uses #token= instead of ?token=. But perhaps that should be a separate question.
Thanks again for this library btw.
This question is likely referring to the OAuth part. An OAuth provider returns the token through the URL when redirecting back to our application. The browser will not send things after the hash to the server, which allows OAuth to keep the token private. This is a very short explanation. Now you'll have a starting point of what to Google for at least :)
Thanks for showing interest, that's really nice to see! This package is very alpha-stage. You might be better off with something like next-auth for now :)