Skip to content

[Bug]: middleware request.geo object is empty #1751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 2 tasks
jadenguitarman opened this issue Nov 7, 2022 · 0 comments · Fixed by #1777
Closed
1 of 2 tasks

[Bug]: middleware request.geo object is empty #1751

jadenguitarman opened this issue Nov 7, 2022 · 0 comments · Fixed by #1777
Labels
type: bug code to address defects in shipped code

Comments

@jadenguitarman
Copy link

jadenguitarman commented Nov 7, 2022

Summary

This is my middleware file:

import { NextResponse } from 'next/server';

export const config = {
	matcher: '/'
};

export const middleware = async request => {
	const response = NextResponse.next();
	response.cookies.set(
		'currentCoords',
		`${request.geo.latitude}, ${request.geo.longitude}`
	);
	return response;
};

I'd expect that this would set a cookie named currentCoords to the coordinates from the request.geo object. However, the request.geo object doesn't have any coordinate information like the Next docs says it should. When I console.log it, I get the city I'm currently in, in the right region and country, but nothing else.

Steps to reproduce

  1. Create a blank repo with the above middleware.
  2. Insert a statement to log the request.geo object to the console.
  3. Visit a page the middleware will intercept.
  4. Observe the logged object, which will not match my expectations above. It's missing coordinate information (which Netlify should have available) and will include the region key as specified in the Next docs instead of the subdivision key from the Netlify docs.

A link to a reproduction repository

https://github.com/jadenguitarman/algolia-next-netlify

Site is live at charleston.netlify.app, site id is 51751fce-133f-4e5b-8cca-fcd5704a9e07

Next Runtime version

4.28.5

More information about your build

  • I am building using the CLI
  • I am building using file-based configuration (netlify.toml)

What OS are you using?

Mac OS

Your netlify.toml file

No response

Your public/_redirects file

No response

Your next.config.js file

`next.config.js`
/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
}

module.exports = nextConfig

Builds logs (or link to your logs)

No response

Function logs

No response

.next JSON files

No response

@jadenguitarman jadenguitarman added the type: bug code to address defects in shipped code label Nov 7, 2022
@MarcL MarcL linked a pull request Nov 16, 2022 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant