# [Solved] How to implement signIn function of NextAuth.js server-side? Cannot get redirect working

J

#### Jasper van Gent

##### Guest
Jasper van Gent Asks: How to implement signIn function of NextAuth.js server-side? Cannot get redirect working
Trying to implement NextAuth.js for a React JS / Next JS project. Currently running React JS 18.2.0, Next JS 13.0.6 and NextAuth.js 4.18.0.

I am using server side rendering with Next API calls deployed on Vercel. For determining a session I am using the unstable_getServerSession inside getServerSideProps, which works fine. Now I would want to use the signIn method to sign in a user with the credentials provider. My implementation keeps redirecting to the same page with some parameters added to the URL:

URL looks like: https://example.com/api/auth/signin?callbackUrl=/

Which displays:

Code:
{"boyd":"","query":{"callbackUrl":"/"},"cookies":{"__Host-next-auth.csrf-token":"token...","__Secure-next-auth.callback-url":"url..."}}

No session is saved and I can't figure out what is going on. I would expect the signin method would resolve this, but I assume that the server-side rendering prevents the call to resolve.

The following code descibes the process of how I implemented this:

Form used:

Code:
<Box component="form" onSubmit={handleSubmit} sx={{ mt: 1 }}>
<input name="csrfToken" type="hidden" defaultValue={csrfToken} />
<TextField
margin="normal"
required
fullWidth
id="phone"
label="Phone Number"
name="phone"
onChange={(e) => setPhone(e.target.value)}
autoComplete="phone"
autoFocus
/>
<TextField
margin="normal"
required
fullWidth
/>
<Button
type="submit"
fullWidth
variant="contained"
sx={{ mt: 3, mb: 2 }}
>
</Button>
</Box>

Form handle:

Code:
const [phone, setPhone] = useState("");
const [submit, setSubmit] = useState(false);

{/* On submit use Next Auth signIn method */}
const handleSubmit = (e) => {
e.preventDefault();
setSubmit(true);
}

useEffect(() => {
if(submit){
signIn("credentials", {
callbackUrl: '/',
})
}
}, [submit])

Getting CSRF-token:

Code:
export async function getServerSideProps(context) {
return {
props: {
csrfToken: await getCsrfToken(context),
},
}
}

And the [...nextauth].js configuration:

Code:
export const authOptions = {
// Authentication providers
providers: [
CredentialsProvider({
id: 'credentials',
name: 'Credentials',
// The credentials is used to generate a suitable form on the sign in page.
// You can specify whatever fields you are expecting to be submitted.
// You can pass any HTML attribute to the <input> tag through the object.
credentials: {
username: { label: "Phone", type: "text" },
},
async authorize(credentials, req){
if(user_data.success){
return user_data.user;
} else{
return null;
}
}
}),
],
session: {
// Choose how you want to save the user session.
// The default is "jwt", an encrypted JWT (JWE) stored in the session cookie.
// If you use an adapter however, we default it to "database" instead.
// You can still force a JWT session by explicitly defining "jwt".
// When using "database", the session cookie will only contain a sessionToken value,
// which is used to look up the session in the database.
strategy: "jwt",

// Seconds - How long until an idle session expires and is no longer valid.
maxAge: 30 * 24 * 60 * 60, // 30 days

// Seconds - Throttle how frequently to write to database to extend a session.
// Use it to limit write operations. Set to 0 to always update the database.
// Note: This option is ignored if using JSON Web Tokens
updateAge: 24 * 60 * 60, // 24 hours

// The session token is usually either a random UUID or string, however if you
// need a more customized session token string, you can define your own generate function.
generateSessionToken: () => {
return uid(32);
}
},
callbacks: {
async signIn({ user, account, profile, email, credentials }) {
return Promise.resolve(true);
},
async redirect({ url, baseUrl }) {
return Promise.resolve(url);
},
async jwt({ token, user, account, profile, isNewUser }) {
return Promise.resolve(token);
},
async session({ session, token, user }) {
// Send properties to the client, like an access_token from a provider.
session.user.image = '';
return Promise.resolve(session);
},
async credentials({ user, account, profile }){
return Promise.resolve(true);
}
},
secret: process.env.NEXTAUTH_SECRET,
pages: {
},
debug: false
}

If you've got any tips on how to fix this, let me know

#### What Is ITIL® v4?

Lora Goody Asks: What Is ITIL® v4?
Specialist in ITIL 4: Adding Value for Stakeholders Expert in Directing, Planning, and Improving ITIL 4 Strategy at High Speed. These lessons will be used by IT professionals who require the technical and practical know-how to oversee dependable IT-enabled teams, services, and workflows. If you want to become an ITIL 4 Strategic Leader or Managing Professional, you must complete all the modules. After doing so, you will have a much better understanding of ITIL and be able to use it successfully.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### [Solved] Count points in a grid

• Aryan Irani
• Geography
• Replies: 0
***** Irani Asks: Count points in a grid
I have a grid that I have created and a path that is there. I want to calculate the number of points each grid has or I want to calculate the number of points each slab or rectangle has.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, solveforum.

#### [Solved] Delete polygons from layer 1 with polygons from layer 2 based on a common attribute between both layers

• epcardiel
• Geography
• Replies: 0
epcardiel Asks: Delete polygons from layer 1 with polygons from layer 2 based on a common attribute between both layers
I have two layers with a large number of polygons. Layer 1 are the polygons I want to crop (green border) and layer 2 are the clipping polygons (red border). Both layers have a common identifier in layer 1 is ID_1 and in layer 2 is ID_2.

The result should be that the polygon of layer 1 with ID_1 =1 is clipped by the polygon of layer 2 with ID_2=1 and so on with all matching polygons.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, solveforum.

#### [Solved] (GEE) constant value after applying scaling factor to LANDSAT

N_LLC Asks: (GEE) constant value after applying scaling factor to LANDSAT
After applying a scaling factor to my LANDSAT collection 2 level 2 data the values seem to be off.

Code:
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['SR_B4', 'SR_B5']).rename('NDVI');
};

var collection1 = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterBounds(sch)
.filterDate('2013-01-01', '2023-01-01')
.select(['SR_B4', 'SR_B5'])

collection1 = collection1.map(
function(img){
.rename('NDVI_rescaled')
}
);

var series1 = ui.Chart.image.seriesByRegion(
collection1, sch, ee.Reducer.mean(), 'NDVI_rescaled', 30, 'system:time_start', 'label')
.setChartType('ScatterChart')
.setOptions({
title: 'L5_SCH_1984-01-01_1986-12-31',
vAxis: {title: 'NDVI'},
lineWidth: 1,
pointSize: 4,
});

print(series1);
//var palette = {min: -1, max: 1, palette: ['blue', 'white', 'green']};
Map.addLayer(collection1);

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, solveforum.

#### Parallel transport in curved spacetime

• Tanmoy Pati
• Physics
• Replies: 0
Tanmoy Pati Asks: Parallel transport in curved spacetime
This is sort of a very introductory question and I am not finding any reference regarding this. And let me know whether my answer is correct or not.

For example, we are parallelly transporting a vector on a surface (intrinsic parallel transport). We take two points and join by a curve and we will do the procedure along the curve. In terms of intrinsic coordinates $P=P(u)$ and $Q=Q(u+du)$. From $P(u)$ if we transport a vector, parallelly, the important condition is $$\nabla_i V^j=0\\ \text{or}, \quad \partial_iV^j=-\Gamma^j_{ik}V^k\\ \text{or,} \quad V_\parallel^j(u+du)=V_\parallel^j(u)-\Gamma^j_{ik}V_\parallel^k(u) du^i+\mathcal{O}(du^2)$$ This transport is done in one path. If we take another path to do the same operation, if $R^a_{bcd} \neq 0$, we will get two different answers for the transported vector component at $Q(u+du)$. So, from the eqn how to interpret this? In particular, there should be some terms which will make $V_\parallel^j(u+du)$ different from one path to another.

Note: These changed $V_\parallel^j(u+du)$ will not make the vector from the point of view of the surface different, since the basis vector also have derivative and have $\Gamma$'s which can cancel the contributions from these $du^n$ terms.

One soln I was thinking, if we take a normal coordinate, for instance, $\Gamma$'s will vanish but $\partial \Gamma$'s will not vanish, hence they actually carry the information of curvature of the manifold. Hence to see actually $V_\parallel^j(u+du)$ are different at different paths, we have to expand upto $du^2$ at least.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### What happens with the tip vortices of two aircraft flying in the opposite direction?

• lWindy
• Physics
• Replies: 0
lWindy Asks: What happens with the tip vortices of two aircraft flying in the opposite direction?
Suppose that an aircraft flies with its wing through an tip vortex of another aircraft which flew in the opposite direction. Suppose that the shed wing tip vortex of both aircraft are exactly the same in strength, only rotating in opposite direction?

What will the net effect be? Will the angular momentum be canceled?

I would like to place this in the light of the existence of a root vortex experienced by wind turbines. From Burton's Wind Energy Handbook (3rd edition, p78) :

" For example, on a two blade rotor, unlike an aircraft wing, the bound circulations on the two blades shown in Figure 3.27 are opposite in sign and so combine in the idealised case of the blade root being at the rotational axis to shed a straight line vortex along the axis with strength equal to the blade circulation times the number of blades. "

With the aircraft example the circulation is opposite in sign as well. So why is the root vortex a summation of the two blades instead of cancellation?

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### Does parallelism of cardinal comparison between sets and their power sets, enact a form of choice?

• Zuhair Al-Johar
• Mathematics
• Replies: 0
Zuhair Al-Johar Asks: Does parallelism of cardinal comparison between sets and their power sets, enact a form of choice?
Let $*$ range over cardinal relations $\{<,=,>, <>\}$, if we add the following axiom to $\sf ZF$, would that prove a known form of choice?

Parallelism: $\forall x \forall y \, ( |x| * |y| \leftrightarrow |\mathcal P(x)| * |\mathcal P| )$

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.